动态生成的数据窗口中的列名称
当我使用 SyntaxFromSQL 动态创建数据存储时(为了基于 SQL SELECT 语句生成数据存储源代码),使用这样的语法,
string ERRORS, sql_syntax, dwsyntax_str, presentation_str
dwsyntax_str = trans_object.SyntaxFromSQL ( sql_syntax, presentation_str, ERRORS)
ds_1.Create( dwsyntax_str, ERRORS)
如何检查数据存储 ds_1
生成的列的名称?我提醒您,在连接两个或多个表的 select 语句的情况下,结果列名可能会在相关的表名之前,例如,我可能会得到一列,而不是获取列名 field_id
名称如:my_table_field_id
。当稍后我提供列名称 (field_id
) 作为 GetItem
函数的参数,而相关数据存储已命名该列 my_table_field_id
时,这会导致问题代码> 代替。
更糟糕的是,我发现我获得不同列定义(前面是表名)的原因之一是用户的登录已被分配 sa 角色
!?!? !
When I dynamically create a datastore using SyntaxFromSQL (in order to generate datastore source code, based on a 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 columns of datastore ds_1
? I remind you that in the case of a select statement that joins two or more tables, the resulting column names may be preceded by the relevant table name e.g. instead of getting the column name field_id
I may get a column name like: my_table_field_id
. This causes problems when later on I provide the column name (field_id
) as an argument of a GetItem
function, while the relevant datastore has named the column my_table_field_id
instead.
To make things worse, I found out that one of the reasons why I was getting different column definitions (preceded by table name) was the fact that the user's login had been assigned the sa role
!?!?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,在Describe()调用中,可以使用列号来代替列名,因此您可以执行以下操作:
缓存值,或者将来只使用列号。大多数引用列的 DataWindow/DataStore 函数都有重载,允许使用整数作为列号而不是字符串作为列名称。
祝你好运,
特里。
Generally, in Describe() calls, the column number can be used in place of the column name, so you can do something like:
Cache the values, or just use the column numbers in the future. Most DataWindow/DataStore functions referencing columns have overloads that allow an integer to be used as a column number instead of a string as the column name.
Good luck,
Terry.
我在使用 SQL Anywhere 11 时遇到了同样的问题,我发现了几个原因。
1) 如果使用 dbUnload 重建数据库,则 systab.creator 的值可能会增加。在这种情况下,您可以获得不同的列名
2)当连接到数据库的用户是表的所有者(创建表的用户)时,我注意到当pb时我得到了my_table_field_id目录表(pbcatcol、pbcattab...)已在数据库中创建。
I had the same problem with SQL Anywhere 11 and i found several causes.
1) If you rebuild a database using dbUnload then the value of systab.creator may be incremented. 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 noted that i got my_table_field_id when the pb catalog tables (pbcatcol, pbcattab, ...) had already been created in the database.