Ruby ODBC Error 37000 (102) Sql syntax error - sql

I have the following ruby database insert using ODBC. Connection is fine.
dbh.do( "INSERT INTO prowlerRunningResults(ProwlerDriver, SourceURL, Title, DestinationURL, FileSource, FileType, FileName, LastModified, FileSize, HashMD5, HashSHA256, ImageBinary)
VALUES (#{driver}, #{source}, #{title}, 'NA', #{imgSrc}, #{fileType}, #{fileName}, #{lastModified}, #{fileSize}, #{md}, #{sha}, #{binary} )" )
However, I am getting an Error message: 37000 (102) [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ','. Which could be a little more helpful considering the number of commas involved. Nevertheless, having looked and looked I simple can't see the problem !!
So to the questions:
Can you detect the syntax error that is being reported?
I would like to insert NULL instead of 'NA' - but have no idea how to do that in ruby. How is it done?
EDIT:
Could be a problem with the DB Schema.
The physical DB has FileSize as an int. So I updated the code to insert #{fileSize.to_i} but the ImageBinary is a varbinary(MAX) - perhaps I could write the file out as HEX to a string? What do you think?

To debug, try looking at the expanded string. You can puts, log, or raise.
sql = "INSERT INTO prowlerRunningResults(ProwlerDriver, SourceURL, Title, DestinationURL, FileSource, FileType, FileName, LastModified, FileSize, HashMD5, HashSHA256, ImageBinary)
VALUES (#{driver}, #{source}, #{title}, 'NA', #{imgSrc}, #{fileType}, #{fileName}, #{lastModified}, #{fileSize}, #{md}, #{sha}, #{binary} )"
puts sql
logger.info sql
raise sql
You probably forgot some single quotes for some string data.

Related

PostgreSQL - Syntax error at or near

There are a lot of questions like this, but I couldn't find one that solved my problem-
Can someone tell me if my syntax is wrong? I'm trying to insert data into a sql table.
INSERT INTO awards values ('Academy of Motion Picture Arts and Sciences’,'2007',’Best Picture','Oscar’);
I'm getting this error:
ERROR: syntax error at or near "2007"
LINE 1: ...s ('Academy of Motion Picture Arts and Sciences’,'2007',’Bes...
Did you paste this from somewhere? Check and replace your quote character, you're using an invalid character (e.g. ’ instead of ') for quoting.

how to run sql including comments?

How I can execute sql statements including comments in pgadmin sql editor?
Neither -- nor /* syntax is working, that is gives me this error:
ERROR: syntax error at or near ""
LINE 1: /*
For comments in PGAdmin SQL editor use -- or /*.... */ notation.
If you use something like
""" comment """
select * from database
you get following syntax error
ERROR: syntax error at or near """" comment """".

how insert ODI step error message in to Oracle table, if the error message has single quotes and colons

I'm trying to insert ODI step error message into oracle table.
I captured the error message using <%=odiRef.getPrevStepLog("MESSAGE")%>.
ODI-1226: Step PRC_POA_XML_synchronize fails after 1 attempt(s).
ODI-1232: Procedure PRC_POA_XML_synchronize execution fails.
ODI-1227: Task PRC_POA_XML_synchronize (Procedure) fails on the source XML connection XML_PFIZER_LOAD_POA_DB_DEV.
Caused By: java.sql.SQLException: class java.sql.SQLException
oracle.xml.parser.v2.XMLParseException: End tag does not match start tag 'tns3:ContctID'.
at com.sunopsis.jdbc.driver.xml.SnpsXmlFile.readDocument(SnpsXmlFile.java:459)
at com.sunopsis.jdbc.driver.xml.SnpsXmlFile.readDocument(SnpsXmlFile.java:469)
When I try to insert this into a table, I'm getting the following error:
Missing IN or OUT parameter at index:: 1
I tried with substr, replace. Nothing works as in middle of the error message we have a single quotes 'tns3:ContctID'.
Is there any way to insert this into a table?
that's a tough one if you want to use pure java BeanShell and you've given way too little details to get short and straight answer, like
how do you try to insert this (command on source/target, bean shell only, Oracle SQL +jBS, jython, groovy etc...)
The problem here is not only quotes but also newlines.
To replace them is even more difficult as every parsing step <%, <?, <# requires different trick to define those literals
What will work for sure is if you write Jython task for inserting log data (Jython in technology).
There you may use Python ability for multiline string literals
simply:
⋮
err_log = """
<?=odiRef.getPrevStepLog("MESSAGE")?>
"""
⋮
I faced this error few days back . I applied below mentioned solution in ODI ...
Use - q'#<%=odiRef.getPrevStepLog("MESSAGE")%>#'
This will escape inverted comma (') for INSERT statement.
I have used this in my code and it is working fine :)
For example -
select 'testing'abcd' from dual;
this query will give below error
"ORA-01756: quoted string not properly terminated"
select q'#testing'abcd#' from dual;
This query gives no error and we get below response in SQL Developer
testing'abcd

Need to add string with \ in it to database

I have a string that is read from an excel file. String is ¬©K!n?8)©}gH"$.F!r'&(®
I keep getting the following error. When running the insert statement
ERROR [42601] [IBM][CLI Driver][DB2/NT] SQL0007N The character "\" following " K!n?8) }gH""$.F!r'" is not valid. SQLSTATE=42601
How do I do this insert with the \ character in the string? The Character causing the problem might also be the &.
Its a DB2 Database
Thanks
It depends on which interface you are sending the insert statement.
In my experience, it is most probably the typewriter single quote character (') which makes the problem.
INSERT INTO TEMP.CHAR_TEST
VALUES ('¬©K!n?8)©}gH"$.F!r''&(®');
works fine for me, but notice that I have changed ' to '' (insert another single quote after the existing one).

Why does MySQL refuse pipe ('|') character in string on INSERT INTO

If I try this statement:
INSERT INTO TerminalEventChild (id,stringValue) VALUES
(64,'version123|');
MySQL fail with :
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''version123' at line 1
SQLState: 42000
ErrorCode: 1064
If I remove the | character, everything works fine. Any idea?
I found the solution on Incorrect query parsing - ID: 3091322.
Squirrel SQL is using the pipe symbol as a procedure/function separator, so you need to change the MySQL preferences to use something else (e.g. |||).
In the "File > Global Preferences > MySQL" tab, in the "Procedure/Function Separator" field,
replace | with a different string, for example |||.
On my machine, this works fine:
CREATE TABLE TerminalEventChild (id INT, stringValue VARCHAR(200));
INSERT INTO TerminalEventChild (id,stringValue) VALUES
(64,'version123|');
Probably, your client treats the pipe character specially.
What client do you use?