Column names in dynamically created data windows

When I dynamically create a datastore using SyntaxFromSQL (to generate the datastore source code based on an SQL SELECT statement), with syntax like this

string ERRORS, sql_syntax, dwsyntax_str, presentation_str dwsyntax_str = trans_object.SyntaxFromSQL ( sql_syntax, presentation_str, ERRORS) ds_1.Create( dwsyntax_str, ERRORS) 

How can I check the names of the generated ds_1 data warehouse columns? I recall that in the case of a select statement that joins two or more tables, the resulting column names may be preceded by the corresponding table name, for example. instead of getting the column name field_id I can get the column name of the type: my_table_field_id . This causes problems when I later provide the column name ( field_id ) as an argument to the GetItem function, while the corresponding data store named the column my_table_field_id .

To make matters worse, I found out that one of the reasons why I was getting different column definitions (with the previous table name) was because the user was assigned the sa role !?!?! Sign!

+4
source share
2 answers

Typically, in the calls to Description (), the column number can be used instead of the column name, so you can do something like:

 string ls_FirstColumnName, ls_SecondColumnName ls_FirstColumnName = dw_1.Describe ("#1.Name") ls_SecondColumnName = dw_1.Describe ("#2.Name") MessageBox ("Column Names", ls_FirstColumnName + "~r~n" + ls_SecondColumnName) 

Download values ​​or just use column numbers in the future. Most column-referenced DataWindow / DataStore functions have overloads that allow you to use an integer as the column number instead of a row as the column name.

Good luck

Terry.

+6
source

I had the same problem with SQL Anywhere 11, and I found several reasons.

1) If you rebuild the database using dbUnload, then the value of systab.creator can be increased. In this case, you can get different column names

2) When the user connected to the database is the owner of the tables (the user who created the tables), I noticed that I got my_table_field_id when the pb directory tables (pbcatcol, pbcattab, ...) were already created in the database.

+1
source

Source: https://habr.com/ru/post/1301097/


All Articles