0

I tries to set styles for all objects in my processing_table, but gets Expression does not evaluate to a column or table name

My code:

'...
pen_style = currentpen() 'get_pen(styles_table_name, obj_type, class_id, selected_scale)
altering_obj = processing_table.obj
alter object altering_obj
    info OBJ_INFO_PEN, pen_style
cmd = "select * from processing_table where objectid = " & id_value & " and class_id = " & class_id & " into one_obj"
run command cmd
update one_obj set obj = altering_obj where rowid = 1 ' Expression does not evaluate to a column or table name error
close table one_obj
'...

And sandbox script works perfectly:

'...
query = "select * from " & selected_layer_name & " where " & id_field_name  & " = " & filter_value & "into filtered"
run command query
id_field = "filtered.objectid"
while not eot(filtered)
    id_value = id_field
    altering_obj = filtered.obj
    alter object altering_obj
        info OBJ_INFO_SYMBOL, point_symbol

    query = "select * from " & selected_layer_name & " where objectid = " & id_value & " into one_obj"
    run command query

    update one_obj set obj = altering_obj where rowid = 1
    close table one_obj
    fetch next from filtered
wend
close table filtered
'...

I can't understand where these scripts are different. Algorithm is same:

  1. Alter object from processing table
  2. Select this object into one_obj table
  3. Update it

Both scripts I checked with same tables. May be reason is in different connection to tables?

In sandbox I use already opened table:

selected_layer_name = layerinfo(window_id, suitable_layers(selected_layer), LAYER_INFO_NAME)
query = "select * from " & selected_layer_name & " where " & id_field_name  & " = " & filter_value & "into filtered"

And in non-working script I opens table from disk:

cmd = "open table " & chr$(34) & tab_file & chr$(34)
run command cmd
table_name = TableInfo(0, TAB_INFO_NAME)
'...
cmd = "select * from " & table_name & " into processing_table"
run command cmd
7
  • set a table name (in your case "processing_table") as a variable (string) and try
    – sys49152
    Mar 4, 2016 at 7:49
  • On what line is the compiler throwing the error? Also, you might want to use a Print command to inspect your cmd variable each time you build a command string (e.g. Print cmd) to make sure that they are being created as you expect. Once you're happy that the command strings are fine then you can comment out or delete those print commands.
    – T_Bacon
    Mar 4, 2016 at 8:36
  • I also get curious when I see people fetching data from a table, changing it and then doing a select before they update the same table again. In your case you get the spatial object from one record, you change it and then you do a select to - probably - select the same record again. You can update the record by referring to the record you just read from using the ROWID Mar 4, 2016 at 8:57
  • Yes, may be I wrote monkey code :) I did it by gathering code samples from Google. Sorry, but I'm beginner in MapBasic and also dislike whole Basic languages family. Mar 4, 2016 at 9:07
  • 1
    Have a look at the ChangeColor function in this thread: gis.stackexchange.com/questions/153164/… Mar 4, 2016 at 9:47

1 Answer 1

0

Error reason was not in above code samples but in code that performs earlier:

query = "select obj from " & selected_layer_name & " where str$(object) = " & chr$(34) & str & chr$(34) & " and class_id = " & class_id & " into temp_obj"
run command query

When I changes select obj ... to select * ... updating became work.

But I still not understood why error happens.

4
  • 1
    Obj is a special field used for accessing the spatial object, it doesn't always work the same as a normal attribute field. I'm pretty sure you can not select just the obj column as you've tried to do. You CAN select a valid attribute column and then refer to the object from the results.
    – T_Bacon
    Mar 4, 2016 at 9:02
  • It's very strange for me. Then why this query worked? After query executing I got access to obj and worked with it. And bug appeared in futher code. Mar 4, 2016 at 9:08
  • Oh, maybe what happened is that by only selecting the special obj field you excluded the other special field RowID. So, when you tried to do the update using RowID it failed to find that column. Speculation as I don't know exactly how it works as I've never only selected obj on it's own from a table.
    – T_Bacon
    Mar 4, 2016 at 9:13
  • No, RowID is not a reason. I tried update table without filtering by row id (in my code updating table has one row, I checked it in browser window) - result was same. Mar 4, 2016 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.