﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Issues  » QueryInformation: SQL Generated for DB2 is incorrect</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 09:34:29 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: QueryInformation: SQL Generated for DB2 is incorrect</title><link>http://forum.strataframe.net/FindPost11260.aspx</link><description>[quote]I know more about PHP/MySQL applications than anything else at the moment[/quote]&lt;/P&gt;&lt;P&gt;Mmm, the good old days.&amp;nbsp; That's where I started my SQL exploits.&amp;nbsp; Still to this day, I think LIMIT instead of TOP.&lt;/P&gt;&lt;P&gt;Don't worry about .NET, though, you'll get the hang of it quickly enough.</description><pubDate>Fri, 31 Aug 2007 08:59:14 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>QueryInformation: SQL Generated for DB2 is incorrect</title><link>http://forum.strataframe.net/FindPost11174.aspx</link><description>I'm hooking into DB2 and it returns a DB2 error when I start view the ASP page:&lt;br&gt;
&lt;br&gt;
[codesnippet][DB2Exception (0x80004005): ERROR [42601] [IBM][DB2/NT] SQL0104N  An unexpected token "[ID_SUPPLIER], [NM_SUPPLIER], [CD_COUNTRY], [IND_STATUS] FROM " was found following "SELECT DISTINCT ".  Expected tokens may include:  "&lt;space&gt;".  SQLSTATE=42601][/codesnippet]&lt;br&gt;
&lt;br&gt;
In this case, I believe the SQL is being generated incorrectly because of the square brackets around each field name - DB2 doesn't accept these. Are there any options I need to set on the QueryInformation object to change how it generates SQL and for what database?&lt;br&gt;
&lt;br&gt;
Thanks in advance!&lt;br&gt;
Peter</description><pubDate>Fri, 31 Aug 2007 08:59:14 GMT</pubDate><dc:creator>PeterA</dc:creator></item><item><title>RE: QueryInformation: SQL Generated for DB2 is incorrect</title><link>http://forum.strataframe.net/FindPost11243.aspx</link><description>[quote][b]Ben Chase (08/30/2007)[/b][hr]Excellent. Glad it's working for you :) &lt;br&gt;
&lt;br&gt;
As for the objects, we tried to keep the names the same as the corresponding ADO.NET provider objects (except for a few cases where the data source uses OLE DB.&lt;br&gt;
&lt;br&gt;
SqlDataSourceItem -&amp;gt; System.Data.SqlClient.SqlCommand&lt;br&gt;
&lt;br&gt;
OracleDataSourceItem -&amp;gt; System.Data.OracleClient.OracleCommand&lt;br&gt;
&lt;br&gt;
Db2DataSourceItem -&amp;gt; IBM.Data.DB2.DB2Command (technically this one accepts a factory, so you can use whatever provider is optimized for your database type since DB2 has several different versions of their ADO.NET provider and we didn't want to limit you)&lt;br&gt;
&lt;br&gt;
VfpDataSourceItem -&amp;gt; System.Data.OleDb.OleDbCommand&lt;br&gt;
&lt;br&gt;
AccessDataSourceItem -&amp;gt; System.Data.OleDb.OleDbCommand[/quote]&lt;br&gt;
&lt;br&gt;
That's good to know and I'll have to keep it in mind. I'd probably have realized that if I'd worked in .NET technologies prior to now (I know more about PHP/MySQL applications than anything else at the moment).&lt;br&gt;
&lt;br&gt;
Thanks!&lt;br&gt;</description><pubDate>Thu, 30 Aug 2007 09:49:15 GMT</pubDate><dc:creator>PeterA</dc:creator></item><item><title>RE: QueryInformation: SQL Generated for DB2 is incorrect</title><link>http://forum.strataframe.net/FindPost11235.aspx</link><description>Excellent.&amp;nbsp; Glad it's working for you :)&amp;nbsp; &lt;/P&gt;&lt;P&gt;As for the objects, we tried to keep the names the same as the corresponding ADO.NET provider objects (except for a few cases where the data source uses OLE DB.&lt;/P&gt;&lt;P&gt;SqlDataSourceItem -&amp;gt; System.Data.SqlClient.SqlCommand&lt;/P&gt;&lt;P&gt;OracleDataSourceItem -&amp;gt; System.Data.OracleClient.OracleCommand&lt;/P&gt;&lt;P&gt;Db2DataSourceItem -&amp;gt; IBM.Data.DB2.DB2Command (technically this one accepts a factory, so you can use whatever provider is optimized for your database type since DB2 has several different versions of their ADO.NET provider and we didn't want to limit you)&lt;/P&gt;&lt;P&gt;VfpDataSourceItem -&amp;gt; System.Data.OleDb.OleDbCommand&lt;/P&gt;&lt;P&gt;AccessDataSourceItem -&amp;gt; System.Data.OleDb.OleDbCommand</description><pubDate>Thu, 30 Aug 2007 09:18:37 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: QueryInformation: SQL Generated for DB2 is incorrect</title><link>http://forum.strataframe.net/FindPost11223.aspx</link><description>Well, I've got it sort of working. I created a static SqlHandler object that is initialized when the request is started and retrieves a connection whenever necessary. Originally, I had it returning a SqlDataSourceItem object, but changed that to Db2DataSourceItem. I had though the SqlDataSourceItem was a generic object rather than one specific to SQL Server.&lt;br&gt;
&lt;br&gt;
I've now got it connected in and pulling data like it should. &lt;br&gt;
&lt;br&gt;
Thanks for your help!</description><pubDate>Wed, 29 Aug 2007 13:25:38 GMT</pubDate><dc:creator>PeterA</dc:creator></item><item><title>RE: QueryInformation: SQL Generated for DB2 is incorrect</title><link>http://forum.strataframe.net/FindPost11211.aspx</link><description>Aha, you're not going through any SF stuff to get there.&amp;nbsp; You're using the System.Web.UI.WebControls.SqlDataSourceView class which is designed to work with SQL Server, so it's creating the query for SQL.&amp;nbsp; DB2 might have a corresponding ASP.NET control.&amp;nbsp; If it doesn't then you might need to fill a DataTable in code and use it to populate the grid (or whatever you're bound to).</description><pubDate>Wed, 29 Aug 2007 10:29:06 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: QueryInformation: SQL Generated for DB2 is incorrect</title><link>http://forum.strataframe.net/FindPost11204.aspx</link><description>[quote][b]Ben Chase (08/29/2007)[/b][hr]You are correct both correct.The "identifier delimiter" used by the different databases for special names is like this:&lt;br&gt;
&lt;br&gt;
SQL Server: [name]&lt;br&gt;
&lt;br&gt;
Oracle: "name"&lt;br&gt;
&lt;br&gt;
DB2: "name"&lt;br&gt;
&lt;br&gt;
Access: [name]&lt;br&gt;
&lt;br&gt;
So, knowing this, we took out all of the [] from the Db2DataSourceItem and replaced them with "". Could you post the stack trace for the error you're getting? It's odd that the Db2DataSourceItem is using [], so I need to track that one down.[/quote]&lt;br&gt;
&lt;br&gt;
Here's the stack trace from my error page:&lt;br&gt;
&lt;br&gt;
   IBM.Data.DB2.DB2Command.a(CommandBehavior A_0, String A_1, DB2CursorType A_2, Boolean A_3, Boolean A_4, Boolean A_5, Int32 A_6) +3973&lt;br&gt;
   IBM.Data.DB2.DB2Command.a(CommandBehavior A_0, String A_1) +47&lt;br&gt;
   IBM.Data.DB2.DB2Command.ExecuteReader(CommandBehavior behavior) +93&lt;br&gt;
   IBM.Data.DB2.DB2Command.ExecuteDbDataReader(CommandBehavior behavior) +33&lt;br&gt;
   System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +7&lt;br&gt;
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +2464&lt;br&gt;
   System.Web.UI.WebControls.Repeater.GetData() +50&lt;br&gt;
   System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +232&lt;br&gt;
   System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +53&lt;br&gt;
   System.Web.UI.WebControls.Repeater.DataBind() +72&lt;br&gt;
   System.Web.UI.WebControls.Repeater.EnsureDataBound() +55&lt;br&gt;
   System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +12&lt;br&gt;
   System.Web.UI.Control.PreRenderRecursiveInternal() +77&lt;br&gt;
   System.Web.UI.Control.PreRenderRecursiveInternal() +161&lt;br&gt;
   System.Web.UI.Control.PreRenderRecursiveInternal() +161&lt;br&gt;
   System.Web.UI.Control.PreRenderRecursiveInternal() +161&lt;br&gt;
   System.Web.UI.Control.PreRenderRecursiveInternal() +161&lt;br&gt;
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360&lt;br&gt;
&lt;br&gt;
Thanks!&lt;br&gt;</description><pubDate>Wed, 29 Aug 2007 09:38:59 GMT</pubDate><dc:creator>PeterA</dc:creator></item><item><title>RE: QueryInformation: SQL Generated for DB2 is incorrect</title><link>http://forum.strataframe.net/FindPost11200.aspx</link><description>You are correct both correct.&amp;nbsp;&amp;nbsp;The "identifier delimiter" used by the different databases for special names is like this:&lt;/P&gt;&lt;P&gt;SQL Server: [name]&lt;/P&gt;&lt;P&gt;Oracle: "name"&lt;/P&gt;&lt;P&gt;DB2: "name"&lt;/P&gt;&lt;P&gt;Access: [name]&lt;/P&gt;&lt;P&gt;So, knowing this, we took out all of the [] from the Db2DataSourceItem and replaced them with "".&amp;nbsp; Could you post the stack trace for the error you're getting?&amp;nbsp; It's odd that the Db2DataSourceItem is using [], so I need to track that one down.</description><pubDate>Wed, 29 Aug 2007 09:27:08 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: QueryInformation: SQL Generated for DB2 is incorrect</title><link>http://forum.strataframe.net/FindPost11196.aspx</link><description>[quote][b]Greg McGuffey (08/28/2007)[/b][hr]Brackets around SQL Server items is OK. This allows for non-compliant names to be used (such as names with spaces or that are key words).  &lt;br&gt;
&lt;br&gt;
Might be nice if there was a way to configure the data source to not use the brackets... :hehe:[/quote]&lt;br&gt;
&lt;br&gt;
Yes, it's OK to use square brackets around fields and tables on SQL Server. I imagine it's OK on Oracle, too (I don't have enough experience to confirm that), but DB2 v9 and DB2 v8 don't allow it. It causes a SQL error to be thrown. I also know of at least one other DB platform (it's not supported by this architecture) that would throw an error.&lt;br&gt;
&lt;br&gt;</description><pubDate>Wed, 29 Aug 2007 07:16:14 GMT</pubDate><dc:creator>PeterA</dc:creator></item><item><title>RE: QueryInformation: SQL Generated for DB2 is incorrect</title><link>http://forum.strataframe.net/FindPost11191.aspx</link><description>Brackets around SQL Server items is OK. This allows for non-compliant names to be used (such as names with spaces or that are key words).  &lt;br&gt;
&lt;br&gt;
Might be nice if there was a way to configure the data source to not use the brackets... :hehe:</description><pubDate>Tue, 28 Aug 2007 17:25:01 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: QueryInformation: SQL Generated for DB2 is incorrect</title><link>http://forum.strataframe.net/FindPost11189.aspx</link><description>Some additional information. I was looking at the source code for the SqlDataSourceItem object and it looks like it will have this kind of trouble on the tables as well.&lt;br&gt;
&lt;br&gt;
The following segment adds the fields to the query:&lt;br&gt;
&lt;br&gt;
[codesnippet]&lt;br&gt;
            If QueryInfo.Fields.Count &gt; 0 Then&lt;br&gt;
                For Each lcField In QueryInfo.Fields&lt;br&gt;
                    loQuery.Append("[")&lt;br&gt;
                    loQuery.Append(lcField)&lt;br&gt;
                    loQuery.Append("], ")&lt;br&gt;
                Next&lt;br&gt;
&lt;br&gt;
                '-- Remove the last two characters ", "&lt;br&gt;
                loQuery.Length -= 2&lt;br&gt;
            Else&lt;br&gt;
                loQuery.Append("*")&lt;br&gt;
            End If&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
It's adding brackets regardless of the database type.  Something similar happens when specifying table names:&lt;br&gt;
&lt;br&gt;
[codesnippet]&lt;br&gt;
            loQuery.Append(" FROM [")&lt;br&gt;
            loQuery.Append(QueryInfo.TableSchema)&lt;br&gt;
            loQuery.Append("].[")&lt;br&gt;
            loQuery.Append(QueryInfo.TableName)&lt;br&gt;
            loQuery.Append("] ")&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
If the database is DB2 v8 (we've not upgraded to v9 yet, but the DB2 Express v9 on my development PC provides the same error), it can't use brackets around the table names either and the query will fail.&lt;br&gt;
&lt;br&gt;
Thanks!&lt;br&gt;
&lt;br&gt;
Peter</description><pubDate>Tue, 28 Aug 2007 16:24:31 GMT</pubDate><dc:creator>PeterA</dc:creator></item></channel></rss>