473,387 Members | 3,787 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.

Valid SQL?

I have this string that I am sending via a Cursor.execute() using
MySQLdb:

insert into table Ping82_eb13__elearn__ihost__com (`dateTime`,
`values`) values(
"Fri May 12 11:39:02 2006", "1")

Does anyone see anything wrong with this SQL syntax?

Thanks,

Harlin Seritt

May 23 '06 #1
5 2120
Harlin Seritt wrote:
I have this string that I am sending via a Cursor.execute() using
MySQLdb:

insert into table Ping82_eb13__elearn__ihost__com (`dateTime`,
`values`) values(
"Fri May 12 11:39:02 2006", "1")

Does anyone see anything wrong with this SQL syntax?


How about a stacktrace?

http://www.catb.org/~esr/faqs/smart-questions.html

And you should use the parametrized version of execute, because then the
DB-API will take care of escaping the strings properly for you. Which is
the problem here, btw: you are using "" for strings, where SQl requires ''.

Diez
May 23 '06 #2
> I have this string that I am sending via a Cursor.execute() using
MySQLdb:

insert into table Ping82_eb13__elearn__ihost__com (`dateTime`,
`values`) values(
"Fri May 12 11:39:02 2006", "1")

Does anyone see anything wrong with this SQL syntax?


While this is the *python* list, rather than a SQL list...

It looks like you're using two diff. styles of quoting. And
using back-quotes at that. IIRC, ANSI-SQL (nebulous standard as
it is, implemented to taste by each vendor) calls for using
single-quotes as strings. Some RDBMS engines support the
double-quote (MySQL does). None that I know of support the
back-tick. Unless it's an RDBMS scheme for surrounding column or
table-names that might have spaces in them (or might be SQL
keywords). You might also want to make sure that your RDBMS
doesn't have a column data-type of "datetime" (MySQL does) which
might choke matters too...having a column-name that potentially
clashes with the name of a datatype is just asking for trouble :)

Additionally, the syntax for INSERT INTO statements usually
leaves the word TABLE as optional. I think this is the first
time I've seen someone opt for it :) Most SQL I've seen just does

INSERT INTO tblFoo (field1, field2) VALUES ('value1', 'value2')

You don't include the DDL that defines the structure of the table
into which you're shoving matters, so it's somewhat hard to tell
what's going on. Are primary keys being violated? Are
data-types awry?

Lastly, you don't include the text of the error message that
you're getting back...most error messages try to be helpful, and
in this case, it would certainly be helpful. :)

Just a few thoughts,

-tkc


May 23 '06 #3
Thanks for the help. I set up the SQL statement to be like:
INSERT INTO tblFoo (field1, field2) VALUES ('value1', 'value2')

I get this error:

insert into Web1_DLTDS10_RootSite (dateTime, values) values('Sat Apr 15
08:58:13
2006', '0')
Traceback (most recent call last):
File "librarian.py", line 45, in ?
Cursor.execute(InsertValuesSQL)
File "C:\Python24\lib\site-packages\MySQLdb\cursors.py", line 137, in
execute
self.errorhandler(self, exc, value)
File "C:\Python24\lib\site-packages\MySQLdb\connections.py", line 33,
in defau
lterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your
SQL syntax
; check the manual that corresponds to your MySQL server version for
the right s
yntax to use near 'values) values('Sat Apr 15 08:58:13 2006', '0')' at
line 1")

Any idea why I'm getting this?

Thanks,

Harlin Seritt

May 23 '06 #4
I am using the exact same query string generated and it works when i
type it in the MySQL client but doesn't work when using the MySQLdb
module.

:(

May 23 '06 #5
Harlin Seritt wrote:
I am using the exact same query string generated and it works when i
type it in the MySQL client but doesn't work when using the MySQLdb
module.


I've been messing around with mysqldb lately, and one reason I get your
error message is if I'm not closing parentheses properly.

Can you paste the exact Python code that you are using here, as well as
the MySQL code used in the client window? I assume in the client you use
a semicolon, but in Python you don't?

I don't know if you'd get that particular error if the problem is
something like the values not matching to their type, especially since
you say it works on the client but not in Python.
May 23 '06 #6

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

Similar topics

12
by: lawrence | last post by:
I have a string which I want to send to eval(). How can I test it ahead of time to make sure it is valid code? I don't want to send it to eval and get parse errors. I want to do something like...
16
by: siliconmike | last post by:
Hi, I'm looking for a reliable script that would connect to a host and somehow determine whether an email address is valid. since getmxrr() only gets the mx records.. Links/pointers ? Mike
1
by: Anna | last post by:
Hi all. I have probably a rather stupid question. If there is an HTML document, XML-formed using JTidy, is there any tool to convert it to valid XHTML? I.e. so that all the tags and attribute...
7
by: JR | last post by:
Hey all, I have read part seven of the FAQ and searched for an answer but can not seem to find one. I am trying to do the all too common verify the data type with CIN. The code from the FAQ...
23
by: James Aguilar | last post by:
Someone showed me something today that I didn't understand. This doesn't seem like it should be valid C++. Specifically, I don't understand how the commas are accepted after the function...
3
by: Chris | last post by:
Hi, In C# I tried to save a file from a generated file name. Just before launching the dialog I check for a valid file name to be sure. There for I used the method ValidateNames from the save...
0
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
1
by: Robert Morgan | last post by:
|I'm trying to run a query on a database using php and postgres functions ||<?php db_connect(); $stat = pg_exec($connstr,"SELECT WSID from tblWorkstation "); while ($row = pg_fetch_rows($stat))...
1
by: illegal.prime | last post by:
Hey all, I have an app, that could take two numbers of any type of numerical type int, long, double, float, uint, ulong, etc. I want to check that the numbers are part of a range that I consider...
10
by: SpreadTooThin | last post by:
Hi I'm writing a python script that creates directories from user input. Sometimes the user inputs characters that aren't valid characters for a file or directory name. Here are the characters...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.