473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Comments in SELECT via PHP/ODBC DB2 UDB v8.1.9 Linux, PHP 4.4.0

Several weeks ago I asked what comments I could pass to DB2 in a SELECT
statement. I don't remember whether I said via PHP/ODBC. I was assured
that both /* */ style comment blocks and -- comment lines were allowed.
Unfortunately, neither work. Both -- and /* */ comments cause a
"premature end of statement". Any sage advice?
Apr 21 '06 #1
7 1856
Bob Stearns wrote:
Several weeks ago I asked what comments I could pass to DB2 in a SELECT
statement. I don't remember whether I said via PHP/ODBC. I was assured
that both /* */ style comment blocks and -- comment lines were allowed.
Unfortunately, neither work. Both -- and /* */ comments cause a
"premature end of statement". Any sage advice?


The /* ... */ should work, I believe. I would be careful with -- style
comments because this will comment out everything till the end of the line
and if PHP strips away the linebreaks, you'll have a problem.

What's the exact error message that you got with?

You might also want to collect a CLI trace (PHP just uses CLI under the
covers). There you will see the exact statement that is send to DB2.

Finally, make sure that you're using the ibm-db2 PHP driver and not the unix
odbc stuff. The latter contains several issues when it comes to DB2.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Apr 21 '06 #2
Knut Stolze wrote:
Bob Stearns wrote:
Several weeks ago I asked what comments I could pass to DB2 in a SELECT
statement. I don't remember whether I said via PHP/ODBC. I was assured
that both /* */ style comment blocks and -- comment lines were allowed.
Unfortunately, neither work. Both -- and /* */ comments cause a
"premature end of statement". Any sage advice?


The /* ... */ should work, I believe. I would be careful with -- style
comments because this will comment out everything till the end of the line
and if PHP strips away the linebreaks, you'll have a problem.

What's the exact error message that you got with?

You might also want to collect a CLI trace (PHP just uses CLI under the
covers). There you will see the exact statement that is send to DB2.

Finally, make sure that you're using the ibm-db2 PHP driver and not the unix
odbc stuff. The latter contains several issues when it comes to DB2.

-- Comments in CLI/ODBC will be supported in V8 FP12.
/* */ are today.

-- Comments in CLP will be supported in DB2 Viper eGA
/* */ are today

JDBC supports both today in the type 4 driver.

I don't now about PHP.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 21 '06 #3

PHP driver is written using CLI/ODBC so It should support /* */
comments as Serge poined out if you are using v8 FP12

FYI : the redbook about PHP and DB2/Informix/Cloudscape development is
in draft state:
may be of help to you.
http://www.redbooks.ibm.com/Redbooks...7218.html?Open

Regards,

Kiran

Apr 21 '06 #4
Kiran wrote:

PHP driver is written using CLI/ODBC so It should support /* */
comments as Serge poined out if you are using v8 FP12


Just a quick correction here: C-style /*...*/ comments are supported
since FP11 (is there an FP12? I thought 11 was the latest?)

As pointed out by Knut, SQL-style -- comments can be problematic as
some clients strip line breaks (which obviously means that anything
after the first -- comment becomes part of the comment ... d'oh!).
Furthermore, as I understand it, DB2 strictly interprets the SQL
standard's definition of SQL-style comments which apparently (I don't
have a copy of the SQL standard, so I can't verify) states that the
opening "--" in SQL-style comments must be the first non-whitespace
characters in the line.

This can be verified by trying it in the CLP (not sure what Serge meant
when he said SQL-style comments will be supported in CLP in Viper as
they've been supported in CLP for several versions now, provided they
adhere to the above rule):

db2 => SELECT
db2 (cont.) => -- This is a valid comment
db2 (cont.) => VARCHAR(SCHEMANAME,8) AS SCHEMANAME
db2 (cont.) => FROM SYSCAT.SCHEMATA;

SCHEMANAME
----------
DOCCAT
DOCDATA
DOCTOOLS
NULLID
SQLJ
SYSCAT
SYSFUN
SYSIBM
SYSPROC
SYSSTAT
SYSTOOLS

11 record(s) selected.

db2 => SELECT -- This is NOT a valid comment
db2 (cont.) => VARCHAR(SCHEMANAME,8) AS SCHEMANAME
db2 (cont.) => FROM SYSCAT.SCHEMATA;
SQL0104N An unexpected token "END-OF-STATEMENT" was found following
"SELECT".
Expected tokens may include: "JOIN <joined_table>". SQLSTATE=42601
HTH,

Dave.

--

Apr 22 '06 #5
Dave Hughes wrote:
Kiran wrote:

PHP driver is written using CLI/ODBC so It should support /* */
comments as Serge poined out if you are using v8 FP12
Just a quick correction here: C-style /*...*/ comments are supported
since FP11 (is there an FP12? I thought 11 was the latest?)


FP12 is not yet out.
As pointed out by Knut, SQL-style -- comments can be problematic as
some clients strip line breaks (which obviously means that anything
after the first -- comment becomes part of the comment ... d'oh!).
Furthermore, as I understand it, DB2 strictly interprets the SQL
standard's definition of SQL-style comments which apparently (I don't
have a copy of the SQL standard, so I can't verify) states that the
opening "--" in SQL-style comments must be the first non-whitespace
characters in the line.
I haven't found this in the standard. SQL:2003 only says in the syntax
rules for "<token> and <separator>":

11) SQL text containing one ore more instances of <comment> is equivalent to
the same SQL statement with the <comment> replaced with <newline>.

<comment> can be a <simple comment>, i.e. -- ...\n, or a <bracketed
comment>, i.e. /* ... */.
This can be verified by trying it in the CLP (not sure what Serge meant
when he said SQL-style comments will be supported in CLP in Viper as
they've been supported in CLP for several versions now, provided they
adhere to the above rule):

db2 => SELECT
db2 (cont.) => -- This is a valid comment
db2 (cont.) => VARCHAR(SCHEMANAME,8) AS SCHEMANAME
db2 (cont.) => FROM SYSCAT.SCHEMATA;

SCHEMANAME
----------
DOCCAT
DOCDATA
DOCTOOLS
NULLID
SQLJ
SYSCAT
SYSFUN
SYSIBM
SYSPROC
SYSSTAT
SYSTOOLS

11 record(s) selected.

db2 => SELECT -- This is NOT a valid comment
db2 (cont.) => VARCHAR(SCHEMANAME,8) AS SCHEMANAME
db2 (cont.) => FROM SYSCAT.SCHEMATA;
SQL0104N An unexpected token "END-OF-STATEMENT" was found following
"SELECT".
Expected tokens may include: "JOIN <joined_table>". SQLSTATE=42601


This looks like a bug in the parser to me.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Apr 24 '06 #6
Knut Stolze wrote:
Dave Hughes wrote:

[snip]
As pointed out by Knut, SQL-style -- comments can be problematic as
some clients strip line breaks (which obviously means that anything
after the first -- comment becomes part of the comment ... d'oh!).
Furthermore, as I understand it, DB2 strictly interprets the SQL
standard's definition of SQL-style comments which apparently (I
don't have a copy of the SQL standard, so I can't verify) states
that the opening "--" in SQL-style comments must be the first
non-whitespace characters in the line.


I haven't found this in the standard. SQL:2003 only says in the
syntax rules for "<token> and <separator>":

11) SQL text containing one ore more instances of <comment> is
equivalent to the same SQL statement with the <comment> replaced with
<newline>.

<comment> can be a <simple comment>, i.e. -- ...\n, or a <bracketed
comment>, i.e. /* ... */.


Interesting, do you happen to have an earlier version of the standard,
say SQL-92 or even SQL-89? I just wonder if the definition has been
changed (well, I guess it has changed to add /*...*/ comments)?
This can be verified by trying it in the CLP (not sure what Serge
meant when he said SQL-style comments will be supported in CLP in
Viper as they've been supported in CLP for several versions now,
provided they adhere to the above rule):

db2 => SELECT
db2 (cont.) => -- This is a valid comment
db2 (cont.) => VARCHAR(SCHEMANAME,8) AS SCHEMANAME
db2 (cont.) => FROM SYSCAT.SCHEMATA;
[snip]
db2 => SELECT -- This is NOT a valid comment
db2 (cont.) => VARCHAR(SCHEMANAME,8) AS SCHEMANAME
db2 (cont.) => FROM SYSCAT.SCHEMATA;
SQL0104N An unexpected token "END-OF-STATEMENT" was found following
"SELECT".
Expected tokens may include: "JOIN <joined_table>". SQLSTATE=42601


This looks like a bug in the parser to me.


Hmmm ... not so sure. A few years ago I wrote a little SQL parser to
handle DB2 syntax and had to thoroughly read the "languages elements",
"tokens", and other bits of the DB2 SQL Reference to make sure it was
right.

I could swear I remember the behaviour described above (-- comments
must be the first non-whitespace characters in a line) mentioned
explicitly in the reference (implying it is intended behaviour).
Unfortunately either my memory is faulty, or that statement's been
excised from the latest version.

Still, it could well be a bug or "feature": I've recently been
discovering how truly bizarre the CLP parser is compared to the SQL
parser (I suspect it's at least partly line-based, instead of "purely"
token-based).

Cheers,

Dave.
--

Apr 24 '06 #7
Dave Hughes wrote:
Knut Stolze wrote:
Dave Hughes wrote:

[snip]
> As pointed out by Knut, SQL-style -- comments can be problematic as
> some clients strip line breaks (which obviously means that anything
> after the first -- comment becomes part of the comment ... d'oh!).
> Furthermore, as I understand it, DB2 strictly interprets the SQL
> standard's definition of SQL-style comments which apparently (I
> don't have a copy of the SQL standard, so I can't verify) states
> that the opening "--" in SQL-style comments must be the first
> non-whitespace characters in the line.


I haven't found this in the standard. SQL:2003 only says in the
syntax rules for "<token> and <separator>":

11) SQL text containing one ore more instances of <comment> is
equivalent to the same SQL statement with the <comment> replaced with
<newline>.

<comment> can be a <simple comment>, i.e. -- ...\n, or a <bracketed
comment>, i.e. /* ... */.


Interesting, do you happen to have an earlier version of the standard,
say SQL-92 or even SQL-89? I just wonder if the definition has been
changed (well, I guess it has changed to add /*...*/ comments)?


SQL92 already used a very similar wording. The only difference is that
bracketed comments were not supported 14 years ago. There were some
restrictions as to the use of comments in dynamic SQL etc.

SQL99 introduced the bracketed comments
> This can be verified by trying it in the CLP (not sure what Serge
> meant when he said SQL-style comments will be supported in CLP in
> Viper as they've been supported in CLP for several versions now,
> provided they adhere to the above rule):
>
> db2 => SELECT
> db2 (cont.) => -- This is a valid comment
> db2 (cont.) => VARCHAR(SCHEMANAME,8) AS SCHEMANAME
> db2 (cont.) => FROM SYSCAT.SCHEMATA;
> [snip] >
> db2 => SELECT -- This is NOT a valid comment
> db2 (cont.) => VARCHAR(SCHEMANAME,8) AS SCHEMANAME
> db2 (cont.) => FROM SYSCAT.SCHEMATA;
> SQL0104N An unexpected token "END-OF-STATEMENT" was found following
> "SELECT".
> Expected tokens may include: "JOIN <joined_table>". SQLSTATE=42601


This looks like a bug in the parser to me.


Hmmm ... not so sure. A few years ago I wrote a little SQL parser to
handle DB2 syntax and had to thoroughly read the "languages elements",
"tokens", and other bits of the DB2 SQL Reference to make sure it was
right.


Maybe that has changed since then. I'm aware that some work is going on to
close many gaps in DB2 that relate to the handling of comments.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Apr 24 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bob | last post by:
OK, PHP newbie here, did a search, but I can't see the forest for the trees now. I need a sanity check to see if I've got this right. Short answers will do fine. 1. PHP includes a native ODBC...
4
by: flupke | last post by:
Hi, at work we use a solid database and i need to develop an application that accesses it. Problem is the drivers: i only have some dll's lying around and jar. On winsdows i could get by by...
5
by: Alex | last post by:
Hi all, We're looking at a vendor who uses the InterSystems Cache Database Platform, but our IT department has zero experience with this system. This software package will have a pivotal and...
10
by: callmebill | last post by:
I'm getting my feet wet with making Python talk to MySQL via ODBC. I started on Windows, and it went smoothly enough due to the ODBC stuff that apparently is native to Python at least on windows...
1
by: Tolik Gusin | last post by:
Hello All, Whether supports DB2 UDB 8.2 FP7 for Linux the ODBC-driver ? If yes, whether that enters this driver into delivery DB2 UDB 8.2 FP7 for Linux ? If it is possible, bring please an...
1
by: Tolik Gusin | last post by:
Hello All, Whether supports DB2 UDB 8.2 FP7 for Linux the ODBC-driver ? If yes, whether that enters this driver into delivery DB2 UDB 8.2 FP7 for Linux ? If it is possible, bring please an...
4
by: pu | last post by:
Hi, Could any one tell me what the following messages means please? And where can I get the error messages with their descriptions? ===begin=== ODBC --call failed. blank (#110) ===end=== I...
3
by: harsha.patibandla | last post by:
We have a webserver, Apache, hosted on Linux and we use php as the scripting language. Now, I am developing a form which will fill up a Microsoft Access database (on a Windows machine). For this...
1
by: Carlos Pena | last post by:
I have MySQL server running fine on Linux Server. I need to connect Windows workstations to the MySQL server. I installed MySQL ODBC 3.51.14 driver. When i try to connect the ODBC allways returns...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.