Problem Inserting zsql query result
Greetings, I would like to insert the results of a query into another table and am doing this from a python script. I am setting the results of a queryequal to a variable with the following: variable = container.zsql_method(paramater=value)[0][0] This gives the results I want (in this case "0"), but when I try to insert this variable using another zsql method, I get the following error: "MySQL server version for the right syntax to use near '0\n)'" The value I want is there, but it has a newline character also. I try removing using .replace but then I get the following error: 'long' object has no attribute 'replace' I would greatly appreciate it if someone could point me in the right direction. Than you very much, Ivan
On 11/11/05, Ivan Stout <aibanhamano@gmail.com> wrote:
Greetings,
I would like to insert the results of a query into another table and am doing this from a python script. I am setting the results of a queryequal to a variable with the following:
variable = container.zsql_method(paramater=value)[0][0]
Try getting the field out by name, not number. Eg: variable = container.zsql_method(paramater=value)[0]['count'] or variable = container.zsql_method(paramater=value)[0]['age']
This gives the results I want (in this case "0"), but when I try to insert this variable using another zsql method, I get the following error:
"MySQL server version for the right syntax to use near '0\n)'"
The value I want is there, but it has a newline character also. I try removing using .replace but then I get the following error:
'long' object has no attribute 'replace'
I would greatly appreciate it if someone could point me in the right direction.
Than you very much,
Ivan
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
Peter, Thank you, but unfortunately I still get the same error due to the newline character being there and still cannot remove it with variable.replace. Can a "long object" be converted to a string or integer some way? On 11/12/05, Peter Bengtsson <peter@fry-it.com> wrote:
On 11/11/05, Ivan Stout <aibanhamano@gmail.com> wrote:
Greetings,
I would like to insert the results of a query into another table and am doing this from a python script. I am setting the results of a queryequal to a variable with the following:
variable = container.zsql_method(paramater=value)[0][0]
Try getting the field out by name, not number. Eg: variable = container.zsql_method(paramater=value)[0]['count'] or variable = container.zsql_method(paramater=value)[0]['age']
This gives the results I want (in this case "0"), but when I try to
insert
this variable using another zsql method, I get the following error:
"MySQL server version for the right syntax to use near '0\n)'"
The value I want is there, but it has a newline character also. I try removing using .replace but then I get the following error:
'long' object has no attribute 'replace'
I would greatly appreciate it if someone could point me in the right direction.
Than you very much,
Ivan
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com <http://www.fry-it.com> home www.peterbe.com <http://www.peterbe.com> hobby www.issuetrackerproduct.com <http://www.issuetrackerproduct.com>
What kind of a strange message is that? "MySQL server version for the right syntax to use near '0\n)'" Is that the ErrorValue? It can't be converted to a long or in because it contains a ) not because of the \n What's the SQL you're trying to use? (Only need to see the SELECT ... part) On 11/11/05, Ivan Stout <aibanhamano@gmail.com> wrote:
Peter,
Thank you, but unfortunately I still get the same error due to the newline character being there and still cannot remove it with variable.replace. Can a "long object" be converted to a string or integer some way?
On 11/12/05, Peter Bengtsson <peter@fry-it.com> wrote:
On 11/11/05, Ivan Stout <aibanhamano@gmail.com> wrote:
Greetings,
I would like to insert the results of a query into another table and am doing this from a python script. I am setting the results of a queryequal to a variable with the following:
variable = container.zsql_method(paramater=value)[0][0]
Try getting the field out by name, not number. Eg: variable = container.zsql_method(paramater=value)[0]['count'] or variable = container.zsql_method(paramater=value)[0]['age']
This gives the results I want (in this case "0"), but when I try to
insert
this variable using another zsql method, I get the following error:
"MySQL server version for the right syntax to use near '0\n)'"
The value I want is there, but it has a newline character also. I try removing using .replace but then I get the following error:
'long' object has no attribute 'replace'
I would greatly appreciate it if someone could point me in the right direction.
Than you very much,
Ivan
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
Yes, the full error message is the following: " ProgrammingError: (1064, "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 '0\n)' at line 9") " Here is the select portion of the query I am running: select count(*) as "order" On 11/12/05, Peter Bengtsson <peter@fry-it.com> wrote:
What kind of a strange message is that? "MySQL server version for the right syntax to use near '0\n)'" Is that the ErrorValue?
It can't be converted to a long or in because it contains a ) not because of the \n What's the SQL you're trying to use? (Only need to see the SELECT ... part)
On 11/11/05, Ivan Stout <aibanhamano@gmail.com> wrote:
Peter,
Thank you, but unfortunately I still get the same error due to the newline character being there and still cannot remove it with variable.replace. Can a "long object" be converted to a string or integer some way?
On 11/12/05, Peter Bengtsson <peter@fry-it.com> wrote:
On 11/11/05, Ivan Stout <aibanhamano@gmail.com> wrote:
Greetings,
I would like to insert the results of a query into another table and am doing this from a python script. I am setting the results of a queryequal to a variable with the following:
variable = container.zsql_method(paramater=value)[0][0]
Try getting the field out by name, not number. Eg: variable = container.zsql_method(paramater=value)[0]['count'] or variable = container.zsql_method(paramater=value)[0]['age']
This gives the results I want (in this case "0"), but when I try to
insert
this variable using another zsql method, I get the following error:
"MySQL server version for the right syntax to use near '0\n)'"
The value I want is there, but it has a newline character also. I try removing using .replace but then I get the following error:
'long' object has no attribute 'replace'
I would greatly appreciate it if someone could point me in the right direction.
Than you very much,
Ivan
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com <http://www.fry-it.com> home www.peterbe.com <http://www.peterbe.com> hobby www.issuetrackerproduct.com <http://www.issuetrackerproduct.com>
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com <http://www.fry-it.com> home www.peterbe.com <http://www.peterbe.com> hobby www.issuetrackerproduct.com <http://www.issuetrackerproduct.com>
Ivan Stout wrote:
Yes, the full error message is the following:
" ProgrammingError: (1064, "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 '0\n)' at line 9") "
Here is the select portion of the query I am running:
select count(*) as "order"
I'd look for the bit of your SQL that is '0' at the end of a line ;-) What's your full ZSQL? (well, actually, boil it down to a minimal test case that fails...) cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Chris, I was preparing to reply to your e-mail when I discovered the problem. I had been assuming it was the query zsql method value that was the problem (due to the "0\n" error), when it was actually a typo in the insert zsql method (I had failed to add a "," when adding the additional field to insert . . . my eyes must be getting old). Anyway, I will try not to make so many assumption when I run it future bugs. Thank you for your help, Ivan On 11/15/05, Chris Withers <chris@simplistix.co.uk> wrote:
Ivan Stout wrote:
Yes, the full error message is the following:
" ProgrammingError: (1064, "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 '0\n)' at line 9") "
Here is the select portion of the query I am running:
select count(*) as "order"
I'd look for the bit of your SQL that is '0' at the end of a line ;-)
What's your full ZSQL? (well, actually, boil it down to a minimal test case that fails...)
cheers,
Chris
-- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Still an amazingly poor error message by your mysql. (perhaps time to upgrade to postgresql :) On 11/15/05, Ivan Stout <aibanhamano@gmail.com> wrote:
Chris,
I was preparing to reply to your e-mail when I discovered the problem. I had been assuming it was the query zsql method value that was the problem (due to the "0\n" error), when it was actually a typo in the insert zsql method (I had failed to add a "," when adding the additional field to insert . . . my eyes must be getting old).
Anyway, I will try not to make so many assumption when I run it future bugs.
Thank you for your help,
Ivan
On 11/15/05, Chris Withers <chris@simplistix.co.uk> wrote:
Ivan Stout wrote:
Yes, the full error message is the following:
" ProgrammingError: (1064, "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 '0\n)' at line 9") "
Here is the select portion of the query I am running:
select count(*) as "order"
I'd look for the bit of your SQL that is '0' at the end of a line ;-)
What's your full ZSQL? (well, actually, boil it down to a minimal test case that fails...)
cheers,
Chris
-- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
En/na Peter Bengtsson ha escrit:
Still an amazingly poor error message by your mysql. (perhaps time to upgrade to postgresql :)
Well, I just started tinkering with postgresql and already had my share of meaningless error messages ;-) And the "Operational Error" in psycopg 2.0b4 wasn't much helpful either :-D (I know, I know, not a postgresql problem, and it's fixed now). Bye -- Luca Olivetti Wetron Automatización S.A. http://www.wetron.es/ Tel. +34 93 5883004 Fax +34 93 5883007
Ivan Stout wrote at 2005-11-11 23:50 +0900:
I would like to insert the results of a query into another table and am doing this from a python script. I am setting the results of a queryequal to a variable with the following:
variable = container.zsql_method(paramater=value)[0][0]
This gives the results I want (in this case "0"), but when I try to insert this variable using another zsql method, I get the following error:
"MySQL server version for the right syntax to use near '0\n)'"
Looks like a stupid error message (I though, only MS and Oracle would produce such stupidies).
The value I want is there, but it has a newline character also. I try removing using .replace but then I get the following error:
'long' object has no attribute 'replace'
Thus, obviously, your "variable" is not a string but a long and a long does not have a newline appended. Your problem must come from elsewhere. "ZSQL Method"s support a "src__" argument. If you pass it with a Python true value (e.g. "1"), then the ZSQL Method is not executed but the generate SQL command returned as source. Carefully look at this source and find out why it is wrong. -- Dieter
participants (5)
-
Chris Withers -
Dieter Maurer -
Ivan Stout -
Luca Olivetti -
Peter Bengtsson