473,657 Members | 2,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Migrated From v7 => v9 ... and Now Can't Use Semi-Colons in Strings?

First off, let me just say that as someone with no DBA training
whatsoever, any help I can get with this issue will be very, very much
appreciated.

My company recently migrated our database from DB2 v7 to DB2 v9. We
hired a consultant to help us, and things went pretty smoothly ... up
until a few weeks after, when a co-worker tried to insert JavaScript
in to our database. That's when we learned that v9, unlike v7, has a
problem with statements such as this one:

INSERT INTO fake.table (fakeId, fakeJavaScript) VALUES (5555, '
function fakeFunction() {
doSomething1();
doSomething2();
}');

Back in v7, I could run "db2 -t", copy/paste that exact code, and the
new record would be created without issue. In v9 however, I find that
the database interprets the above as three separate statements:

#1
INSERT INTO fake.table (fakeId, fakeJavaScript) VALUES (5555, '
function fakeFunction() {
doSomething1();

#2
doSomething2();

#3
}');

Because it recognizes the semi-colon as a termination character even
though it is part of a string literal. This new behavior was
frustrating to discover, but what was even more frustrating was that
(even after I spent several hours Googling) I was unable to find any
way at all to reverse it. In fact, the only "solution" I was able to
find was "change your termination character".

Unfortunately, changing the termination character doesn't really solve
the problem, because I can't guarantee that the character I change it
to won't someday be used in a string literal (in fact, I can pretty
much guarantee the exact opposite; we use lots of weird characters).
Thus, the only real solution I can see is if I can find a way to tell
DB2 to let quotes trump termination characters.

Does such an option, or anything even close, exist? And if not, is
there perhaps some other way of resolving this issue that I haven't
considered? Of course, answers/suggestions would be great, but even
any further background information would really help me out.

Thanks,
Jeremy
Jun 27 '08 #1
26 3029
On Jun 20, 3:04 am, machineghost <machinegh...@g mail.comwrote:
First off, let me just say that as someone with no DBA training
whatsoever, any help I can get with this issue will be very, very much
appreciated.

My company recently migrated our database from DB2 v7 to DB2 v9. We
hired a consultant to help us, and things went pretty smoothly ... up
until a few weeks after, when a co-worker tried to insert JavaScript
in to our database. That's when we learned that v9, unlike v7, has a
problem with statements such as this one:

INSERT INTO fake.table (fakeId, fakeJavaScript) VALUES (5555, '
function fakeFunction() {
doSomething1();
doSomething2();

}');

Back in v7, I could run "db2 -t", copy/paste that exact code, and the
new record would be created without issue. In v9 however, I find that
the database interprets the above as three separate statements:

#1
INSERT INTO fake.table (fakeId, fakeJavaScript) VALUES (5555, '
function fakeFunction() {
doSomething1();

#2
doSomething2();

#3

}');

Because it recognizes the semi-colon as a termination character even
though it is part of a string literal. This new behavior was
frustrating to discover, but what was even more frustrating was that
(even after I spent several hours Googling) I was unable to find any
way at all to reverse it. In fact, the only "solution" I was able to
find was "change your termination character".

Unfortunately, changing the termination character doesn't really solve
the problem, because I can't guarantee that the character I change it
to won't someday be used in a string literal (in fact, I can pretty
much guarantee the exact opposite; we use lots of weird characters).
Thus, the only real solution I can see is if I can find a way to tell
DB2 to let quotes trump termination characters.

Does such an option, or anything even close, exist? And if not, is
there perhaps some other way of resolving this issue that I haven't
considered? Of course, answers/suggestions would be great, but even
any further background information would really help me out.

Thanks,
Jeremy
This behavior exists in 9.5 as well. The problem seem to exists when ;
is at the end of a line. As a workaround you could try:

INSERT INTO fake.table (fakeId, fakeJavaScript)
VALUES (5555, 'function fakeFunction() {
doSomething1(); //
doSomething2(); //
}');

It sure looks like a bug, so I think you should open a pmr. Please do
report back here whether it is a bug or if it works as intended.

/Lennart
Jun 27 '08 #2
Ian
machineghost wrote:
First off, let me just say that as someone with no DBA training
whatsoever, any help I can get with this issue will be very, very much
appreciated.

My company recently migrated our database from DB2 v7 to DB2 v9. We
hired a consultant to help us, and things went pretty smoothly ... up
until a few weeks after, when a co-worker tried to insert JavaScript
in to our database. That's when we learned that v9, unlike v7, has a
problem with statements such as this one:
I suspect that the CLP (the 'db2' command line processor) probably got
a little more strict in V8 due to all of the new features.

The solution is to change your statement terminator. Use an '@' or
something else...

INSERT INTO fake.table (fakeId, fakeJavaScript) VALUES (5555, '
function fakeFunction() {
doSomething1();
doSomething2();
}')@
Then, run with 'db2 -td@ -f <file>'

Jun 27 '08 #3
On Jun 20, 9:02 am, Ian <ianb...@mobile audio.comwrote:
machineghost wrote:
First off, let me just say that as someone with no DBA training
whatsoever, any help I can get with this issue will be very, very much
appreciated.
My company recently migrated our database from DB2 v7 to DB2 v9. We
hired a consultant to help us, and things went pretty smoothly ... up
until a few weeks after, when a co-worker tried to insert JavaScript
in to our database. That's when we learned that v9, unlike v7, has a
problem with statements such as this one:

I suspect that the CLP (the 'db2' command line processor) probably got
a little more strict in V8 due to all of the new features.

The solution is to change your statement terminator. Use an '@' or
something else...

INSERT INTO fake.table (fakeId, fakeJavaScript) VALUES (5555, '
function fakeFunction() {
doSomething1();
doSomething2();

}')@

Then, run with 'db2 -td@ -f <file>'
I'm afraid that wont help in general. Assume a codesnippet like:

INSERT INTO fake.table (fakeId, fakeJavaScript)
VALUES (5555, 'function fakeFunction() {
doSomething1(); // jadajada @
doSomething2(); //
}') @

i.e. a line that ends with stmt terminator. To me it looks like a bug
in the lexical parser, but I'm not sure how it is supposed to work.

/Lennart
Jun 27 '08 #4
Lennart wrote:

[snip]
i.e. a line that ends with stmt terminator. To me it looks like a bug
in the lexical parser, but I'm not sure how it is supposed to work.
I agree this definitely looks like a bug. However, the CLP parser is a
strange beastie to say the least. Before I veer off on a long tangent
about just how weird the CLP's parser is, here's a suggestion for the
OP:

While I doubt you'll be able to work around this "properly" in the CLP,
you shouldn't have any trouble with statements including multi-line
strings with semi-colons at the end in other interfaces, e.g. ODBC,
JDBC, CLI, etc. especially as these interfaces can only execute a
single statement at a time and have no concept of a statement
terminator (the terminator is simply the end of the string containing
the statement).

For example:

$ db2 "CREATE TABLE TEST (S VARCHAR(1000) NOT NULL)"
DB20000I The SQL command completed successfully.
$ python
Python 2.5.1 (r251:54863, Oct 5 2007, 13:50:07)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>import DB2
conn = DB2.connect('SA MPLE')
cur = conn.cursor()
cur.execute(" ""INSERT INTO TEST (S) VALUES ('function
fakeFunction() {
.... doSomething1();
.... doSomething2();
.... }')""")
1
>>conn.commit ()
cur.close()
conn.close( )
^D
$ db2 "select * from test2"

S

----------------------------------------------------------------...
function fakeFunction() {
doSomething1();
doSomething2();
}
1 record(s) selected.
So ... the weirdness of the CLP's parser ...

A while back I wrote a parser for DB2's SQL dialect, i.e. just the
statements listed under the SQL reference in the InfoCenter. This went
reasonably smoothly, with no surprises (except the sheer size of the
damned thing). Then I wanted to add the CLP commands to the parser (the
statements listed under the Commands topic of the InfoCenter before
they got moved somewhere in 9.5). This turned out to be nightmarishly
difficult as the CLP commands have fundamentally different syntax.

Consider the EXPORT command. You can use any of the following
legitimately with it:

EXPORT TO filename.ixf OF IXF ...
EXPORT TO 'filename.ixf' OF IXF ...
EXPORT TO "filename.i xf" OF IXF ...
EXPORT TO C:\filename.ixf OF IXF ...

So, what's the syntax? In SQL terms, the filename can be a string
literal, a quoted identifier, an unquoted identifier, or a sequence of
unquoted identifiers, operators (.), and characters that are generally
illegal in SQL (: and \). If you think that's weird, try the following:

$ db2 -t "EXPORT TO ;.IXF OF IXF SELECT * FROM SOMETABLE;"

It shouldn't work. The EXPORT command should be terminated at the first
semi-colon. But it /does/ work (and has for some time now - since v7 at
least, I think). You can get a hint as to how the CLP is parsing stuff
by breaking the statement above (remove the TO)

$ db2 -t "EXPORT ;.IXF OF IXF..."
SQL0104N An unexpected token ";.IXF" was found following "EXPORT".
Expected tokens may include: "TO". SQLSTATE=42601

So ;.IXF is considered a single token. For another hint, stick a space
in the filename and quote it:

$ db2 -t "EXPORT '; .IXF' OF IXF..."
SQL0104N An unexpected token "'; .IXF'" was found following "EXPORT".
Expected tokens may include: "TO". SQLSTATE=42601

So '; .IXF' is also a single token. It looks like the CLP tokenizer is
just doing whitespace splitting, with some extra logic to handle quoted
stuff. I wouldn't be too surprised if the CLP used a regex similar to
the following to tokenize its input:

("([^"]|"")*"|'([^']|'')*'|[^ ]+)

Given this, how does it recognize a statement terminator? Are
terminators at the end of a token are counted?

$ db2 -t "EXPORT TO IXF; OF IXF SELECT * FROM TEST;"

No - that works just fine (exports to a file called "IXF;"). Are
terminators at the end of a statement counted? (i.e. where a parser
would "expect" to find them):

$ db2 -t "EXPORT TO TEST.IXF OF IXF SELECT * FROM TEST;IMPORT FROM
TEST.IXF OF IXF REPLACE INTO TEST;"

No - this fails complaining about the table name ("TEST;IMPOR T") being
invalid. Given the ambiguities of SELECT in SQL, I tried reversing the
statments above, and again it complains (in a slightly different
manner) that TEST;EXPORT is an invalid table name. Adding spaces after
the terminators makes no difference either (well, it changes the errors
but they still aren't correctly recognized as terminators).

Basically, terminators are recognized if and only if they occur at the
end of a line, so there's some line-wise logic in there too. I'm quite
surprised that multi-line strings containing semi-colon at the end of a
line within the string worked in v7. Of all the ways I can imagine the
CLP's parser being written (given the behaviour above), a change that
broke this functionality is not a subtle or simple one - I /think/ it
would have to involve the removal of quite a bit of code.

At the end of the day, I would have much preferred it if the CLP had a
"real" parser, even if that meant that things like filenames (or
usernames or passwords) had to be specified as string literals. The
language would be more strict, but at least edge cases like multi-line
strings with terminators, or filenames containing terminators, or
multiple statements on a line, would behave predictably. Unfortunately
I suspect the demands of backward compatibility mean it's unlike to
happen.

Still, I'd also recommend opening a PMR for this issue. It should be
made to work (even if it does mean the CLP's "parser" gets even more
weird ;-).
Cheers,

Dave.
Jun 27 '08 #5
Wow, thanks for the replies everyone. It seems I'm facing a genuine
bug here, and that my only real options are to:

A) Set a character that I believe to be the rarest/least used as our
termination character, modify all my SQL-generating code to use this
new termination character, and then hope/pray that we never have any
SQL which includes this character followed by a newline.

B) Re-architect our system to run the SQL code via Java, rather than
at the command line.

Both will be a pain, but option B) seems like a more stable/
predictable fix, so I guess I'd better start working on it :-)

Thanks again for all the help,
Jeremy
Jun 27 '08 #6
I'll see if I can find the notes when I get back to the server but you
should be able to track it down from this info - or maybe it will jog some
memories on the list here.
I tried searching the list for the post you mentioned, but was unable
to find anything. The only parameters I am aware of are the ones you
get from db2 ? OPTIONS:

-a Display SQLCA
-c Auto-commit
-d Retrieve and display XML declarations
-e Display SQLCODE/SQLSTATE
-f Read from input file
-i Display XML data with indentation
-l Log commands in history file
-m Display the number of rows affected
-n Remove new line character
-o Display output
-p Display db2 interactive prompt
-q Preserve whitespaces and linefeeds
-r Save output report to file
-s Stop execution on command error
-t Set statement termination character
-v Echo current command
-w Display FETCH/SELECT warning messages
-x Suppress printing of column headings
-z Save all output to output file

I have tried using -q and -n, but neither resulted in the behavior you
described, and none of the other options seem appropriate.

I would be extremely grateful if you could provide the syntax for the
'revert "new" parsing' option you described, or even some suggestion
as to how I might find the post you referred to.

Jeremy
Jun 27 '08 #7
machineghost wrote:
Wow, thanks for the replies everyone. It seems I'm facing a genuine
bug here, and that my only real options are to:

A) Set a character that I believe to be the rarest/least used as our
termination character, modify all my SQL-generating code to use this
new termination character, and then hope/pray that we never have any
SQL which includes this character followed by a newline.

B) Re-architect our system to run the SQL code via Java, rather than
at the command line.

Both will be a pain, but option B) seems like a more stable/
predictable fix, so I guess I'd better start working on it :-)
C) Call support
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 27 '08 #8
C) Call support
Why didn't I think of that? I guess I use too much (often
unsupported) open source software ...

Anyhow, I did call Support as soon as I saw your thread, but it ended
up being fruitless. We're running our DB2 on Ubuntu Linux, which
evidently is not a supported distribution. I wouldn't think that the
distribution would matter, but whether it does or not is irrelevant as
far as the IBM Support is concerned. Which means I'm back to choosing
between A) and B) ...

.... unless Will responds with potential option D)?
(Please?)

Jeremy
Jun 27 '08 #9
machineghost wrote:
C) Call support
Why didn't I think of that? I guess I use too much (often
unsupported) open source software ...

Anyhow, I did call Support as soon as I saw your thread, but it ended
up being fruitless. We're running our DB2 on Ubuntu Linux, which
evidently is not a supported distribution. I wouldn't think that the
distribution would matter, but whether it does or not is irrelevant as
far as the IBM Support is concerned. Which means I'm back to choosing
between A) and B) ...
On the contrary: Ubuntu 6.06 (Dapper) is validated with DB2 9 [1],
Ubuntu 7.04 (Edgy) is validated with DB2 9.5, while Ubuntu 7.10
(Feisty) is supported with DB2 9.5 [2].

Are you perhaps using 8.04 (Gutsy), the latest LTS release? If so, grab
a spare box, throw Feisty and DB2 on there and reproduce the error
(obviously it's not going to change anything, but it ought to be
sufficient to satisfy the support droids).

[1]
http://www.ibm.com/developerworks/wi...+Recommended+L
inux+Environmen ts

[2]
http://www.ibm.com/developerworks/wi...+for+Linux+-+S
upported+Enviro nments
Cheers,

Dave.
Jun 27 '08 #10

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

Similar topics

1
1804
by: Wolfgang Keller | last post by:
Hello, just as an introduction: I'm not a developer by profession, I just need a solution for this within the scope of a single project... What I am looking for is basically a tool (usable for non-developers) to (semi-)automatically create a relational database schema (MySQL) from an ..xsd schema (and vice-versa) as well as to generate entries into the database from an XML document (and vice-versa).
2
3772
by: Dennis M. Marks | last post by:
I am never sure of when a semi-colon is required in javascript. Is there a definite rule? -- Dennis M. Marks -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
13
2179
by: Chris Goldie | last post by:
From an accessibility point of view, is there any advange in using <P> over <br>? eg, whats the difference between these two examples, are they both accessible? Eg. 1 <p>My first paragraph.</p> <p>My second paragraph.</p>
0
2728
by: Jean-Marc Blaise | last post by:
Dear all, I would like to signal an inconvenience with the db2imigr, if root's environment points to a DB2 instance (Aix). We did a /usr/opt/db2_08_01/db2ckmig .... worked ok saying db(s) can be migrated. Then /usr/opt/db2_08_01/db2imigr inst1 ... that did again the db2ckmig ok, then failed with "DBI1124E Instance inst1 cannot be migrated."
14
2019
by: TT (Tom Tempelaere) | last post by:
Hi people, The code that follows throws an ExecutionEngineException. This was written in C# (Microsoft Visual C# .NET 69462-335-0000007-18823) using MSDE 7.1 (7.1.3088). The framework is .NET 1.1 (1.1.4322). I tested the program on a Windows XP Professional/SP1, with a Pentium 4/2.6Ghz processor, with 2Gb RAM. The code is a single form that when run throws an ExecutionEngineException in 'AddRowsToTable'. If someone with more...
2
2011
by: techiepundit | last post by:
I'm parsing some data of the form: OuterName1 InnerName1=5,InnerName2=7,InnerName3=34; OuterName2 InnerNameX=43,InnerNameY=67,InnerName3=21; OuterName3 .... and so on.... These are fake names I've made up to illustrate the point more clearly. (the embedded device device can't produce XML and this is what I have
2
2312
by: James Stroud | last post by:
Hello All, I am trying to create a semi-standalone with the vendor python on OS X 10.4 (python 2.3.5). I tried to include some packages with both --packages from the command and the 'packages' option in setup.py. While the packages were nicely included in the application bundle in both cases (at Contents/Resources/lib/python2.3/), they were not found by python when the program was launched, giving the error: "ImportError: No module...
0
1070
by: Gops | last post by:
I've find out few XML Node differences in the Migrated word 2007 document and Native Word documnet 2007 Open XML format. For Example, In Migrated word 2007 <w:p> <w:pPr> <w:numPr> <w:ilvl w:val="0" /> <w:numId w:val="1" /> </w:numPr>
1
6056
by: rynato | last post by:
I have a <spanof width X px and height Y px. I want to read the text of an article, which is stored in a mySQL table, and pass to that <spanonly just enough text to fit in it, along with a 'read more' hyperlink which will take the user to the full article. I do not want any overflow scroll bars to show. The font-size is set by external stylesheet in em's. How can I determine how much text is enough? Approaches I've thought of:
1
1513
by: jej1216 | last post by:
Background: I have an PHP form that inserts data into a MySQL DB, and it works. Severity of Incident: <select name="severity" size="1"> <option value="">Select a Severity Option</option> <option value="Level1 - No Obvious Harm">Level 1 - No Obvious Harm</option> <option value="Level2 - Non-permanent Harm">Level 2 - Non-permanent Harm</option> <option value="Level3 - Semi-permanent Harm">Level 3 - Semi-permanent Harm</option> <option...
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.