Simple CGI request and Python reply
Hello, I'm trying to implement something very simple without using a Python WebFramework and I need some advice. I want to send a comma delimited string from the client to a server-side Python script. My initial plan was to use a JavaScript function (see below) called "makerequest" that creates a XMLHttpRequest object and GETs the output from a Python script. I've used this function before to field requests (in those cases the parameter "data" passed in the XMLHttpRequest.send() method is null). So I thought I could just pass some data in and be able to retrieve it with Python. I'm not sure how to do this. I've used forms with cgi/Python before. However, I don't want to use a form here. I want Python to handle the "data" variable being passed without looking for field names using .FieldStorage(). Can that be done? Maybe making a request is not the quickest route to do what I want. Ideas? function makerequest(serverPage,objID,data) { var obj = document.getElementById(objID); xmlhttp.open("GET",serverPage); xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { obj.innerHTML = xmlhttp.responseText; } } xmlhttp.send(data); } -- View this message in context: http://www.nabble.com/Simple-CGI-request-and-Python-reply-tp22952274p22952274.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Mx.ODBC insert error
Thanks John. I now see it John Machin wrote: > > On Jan 30, 3:27 am, Greg Corradini <[EMAIL PROTECTED]> wrote: >> Hello, >> I've never gotten this traceback error before using mx.ODBC. > > "traceback error"?? I see no problem with the traceback. > >> Any ideas about >> resolving this issue? The statement and the error it generates are listed >> below. > > The error was "generated" by you. The error message was generated by > "[Microsoft][ODBC Microsoft Access Driver]" > >> >> curse.execute("Insert into FHWA_StandSamp_2008(LRS_ID_NEW) >> values('040210') where LRS_ID = '0403700010'") >> >> Traceback (most recent call last): >> File "", line 1, in ? >> curse.execute("Insert into FHWA_StandSamp_2008(LRS_ID_NEW) values >> ('040210') where LRS_ID = '0403700010'") >> ProgrammingError: ('37000', -3516, '[Microsoft][ODBC Microsoft Access >> Driver] Missing semicolon (;) at end of SQL statement.', 4612) >> > > Like it says, ProgrammingError. > > Try > INSERT INTO table (columns) VALUES (values) > or > INSERT INTO table (columns) > SELECT stuff FROM somewhere [WHERE boolean_expression] > or perhaps even > UPDATE table SET column = expression WHERE boolean_expression > > Perhaps you could consider avoiding combining random fragments of SQL > or English and hoping for tolerant fuzzy parsing by the recipient :-) > > HTH, > John > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Mx.ODBC-insert-error-tp15163149p15166795.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Mx.ODBC insert error
Hello, I've never gotten this traceback error before using mx.ODBC. Any ideas about resolving this issue? The statement and the error it generates are listed below. curse.execute("Insert into FHWA_StandSamp_2008(LRS_ID_NEW) values('040210') where LRS_ID = '0403700010'") Traceback (most recent call last): File "", line 1, in ? curse.execute("Insert into FHWA_StandSamp_2008(LRS_ID_NEW) values ('040210') where LRS_ID = '0403700010'") ProgrammingError: ('37000', -3516, '[Microsoft][ODBC Microsoft Access Driver] Missing semicolon (;) at end of SQL statement.', 4612) Thanks Greg -- View this message in context: http://www.nabble.com/Mx.ODBC-insert-error-tp15163149p15163149.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Understanding mxODBC Insert Error
Hello, I'm trying to perform a simple insert statement into a table called Parcel_Test (see code below). Yet, I get an error message that I've never seen before (see traceback below). I've tried to put a semicolon at the end of the sql statement, but with no luck. Any ideas from more experienced mx.ODBC users? CODE >>> driv='DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+workspace >>> conn = odbc.DriverConnect(driv) >>> crs = conn.cursor() >>> sql = "INSERT into Parcel_Test(NEAR_FID,NEAR_DIST) values >>> ('0.00','0.00') where PIN_ID = '042822120008'" >>> crs.execute(sql) TRACEBACK Traceback (most recent call last): File "", line 1, in ? crs.execute(sql) ProgrammingError: ('37000', -3516, '[Microsoft][ODBC Microsoft Access Driver] Missing semicolon (;) at end of SQL statement.', 4612) -- View this message in context: http://www.nabble.com/Understanding-mxODBC-Insert-Error-tf4166125.html#a11852950 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Boolean confusion
On 2007-05-09, Greg Corradini <[EMAIL PROTECTED]> wrote: > > Hello all, > I'm having trouble understanding why the following code evaluates as it > does: > >>>> string.find('020914A','.') and len('020914A') > 10 > True >>>> len('020914A') > 10 and string.find('020914A','.') > -1 > > In the 2.4 Python Reference Manual, I get the following explanation for > the > 'and' operator in 5.10 Boolean operations: > " The expression x and y first evaluates x; if x is false, its value is > returned; otherwise, y is evaluated and the resulting value is returned." > > Based on what is said above, shouldn't my first expression ( > string.find('020914A','.') and len('020914A') > 10) evaluate to > false b/c my 'x' is false? And shouldn't the second expression evaluate to > True? >The find method doesn't return a boolean, but returns the index where >the substring was found with -1 indicating it wasn't found. If you just >want to check wether one string is a substring of an other, use the in >operator. >>> '.' in '020914A' and len('020914A') > 10 False >>> len('020914A') > 10 and '.' in '020914A' False Thank you Diez and Antoon for demystifing this problem. I see where I've been going wrong. -- View this message in context: http://www.nabble.com/Boolean-confusion-tf3715438.html#a10393765 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Boolean confusion
Thank you Diez and Antoon for demystifing this problem. I see where I've been going wrong. Diez B. Roggisch-2 wrote: > > Greg Corradini wrote: > >> >> Hello all, >> I'm having trouble understanding why the following code evaluates as it >> does: >> >>>>> string.find('020914A','.') and len('020914A') > 10 >> True >>>>> len('020914A') > 10 and string.find('020914A','.') >> -1 >> >> In the 2.4 Python Reference Manual, I get the following explanation for >> the 'and' operator in 5.10 Boolean operations: >> " The expression x and y first evaluates x; if x is false, its value is >> returned; otherwise, y is evaluated and the resulting value is returned." >> >> Based on what is said above, shouldn't my first expression ( >> string.find('020914A','.') and len('020914A') > 10) evaluate to >> false b/c my 'x' is false? And shouldn't the second expression evaluate >> to >> True? > > The first evaluates to True because len(...) > 10 will return a boolean - > which is True, and the semantics of the "and"-operator will return that > value. > > And that precisely is the reason for the -1 in the second expression. > > y=-1 > > and it's just returned by the and. > > in python, and is implemented like this (strict evaluation > nonwithstanding): > > def and(x, y): > if bool(x) == True: >return y > return x > > Diez > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Boolean-confusion-tf3715438.html#a10393705 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Boolean confusion
Hello all, I'm having trouble understanding why the following code evaluates as it does: >>> string.find('020914A','.') and len('020914A') > 10 True >>> len('020914A') > 10 and string.find('020914A','.') -1 In the 2.4 Python Reference Manual, I get the following explanation for the 'and' operator in 5.10 Boolean operations: " The expression x and y first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned." Based on what is said above, shouldn't my first expression ( string.find('020914A','.') and len('020914A') > 10) evaluate to false b/c my 'x' is false? And shouldn't the second expression evaluate to True? Thanks for your help Greg -- View this message in context: http://www.nabble.com/Boolean-confusion-tf3715438.html#a10393362 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: 1.#QNAN Solution
Thanks for you help Grant Grant Edwards wrote: > > On 2007-05-08, Greg Corradini <[EMAIL PROTECTED]> wrote: > >> I'm running descriptive stats on mileages from a database >> (float numbers, about a million records). My sum returns >> 1.#QNAN, which I understand from searching this forum is an >> error. > > Not necessarily. You've ended up with a floating point "not a > number" value (AKA a NaN). That might or might not be an > error. Whether it's an error not not depends on your input > data and your algorithm. > >> While I'm looking for help in solving this problem, I'm more >> interested in a general explanation about the cause of this >> problem. > > If you're asking how you end up with a NaN, there are several > ways to generate a NaN: > > 0/0 > > Inf*0 > > Inf/Inf > > Inf-Inf > > Almost any operation on a NaN > > http://en.wikipedia.org/wiki/NaN > http://steve.hollasch.net/cgindex/coding/ieeefloat.html > > -- > Grant Edwards grante Yow! Spreading peanut > at butter reminds me of >visi.comopera!! I wonder why? > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/1.-QNAN-Solution-tf3710941.html#a10382201 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
1.#QNAN Solution
Hello all, I'm running descriptive stats on mileages from a database (float numbers, about a million records). My sum returns 1.#QNAN, which I understand from searching this forum is an error. While I'm looking for help in solving this problem, I'm more interested in a general explanation about the cause of this problem. Any ideas? Thanks Greg Corradini -- View this message in context: http://www.nabble.com/1.-QNAN-Solution-tf3710941.html#a1037 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help Understanding mx.ODBC Error
Steve Holden wrote: > > Greg Corradini wrote: > [actually, her wrote it here but I moved it to the bottom] >> Steve Holden wrote: >>> Greg Corradini wrote: >>>> Hello All, >>>> A few weeks ago, I wrote two scripts using mx.ODBC on an Access DB. >>>> Among >>>> other things, both scripts create new tables, perform a query and then >>>> populate the tables with data in a dictionary that I've uploaded from >>>> elsewhere. These scripts have run hundreds of times in the last few >>>> weeks >>>> with no problems. >>>> >>>> But recently they continue to bail on the mycursor.execute('An SQL >>>> Statement') after the table has been created. I get the following error >>>> message: >>>> Traceback (most recent call last): >>>> File "C:\Documents and Settings\marv1shi\Desktop\Workspace\Existence >>>> Script\DBF Checker\Access_SQL.py", line 35, in ? >>>> curse.execute(sql) >>>> ProgrammingError: ('07001', -3010, '[Microsoft][ODBC Microsoft Access >>>> Driver] Too few parameters. Expected 4.', 4612) >>>> >>>> The real stinker, however, is that after it bails I can manually call >>>> mycursor.execute('An SQL Statement'), then call my insert statement in >>>> the >>>> Python Shell and it works fine. >>>> >>>> I just can't figure out how to reconcile this problem. Has anybody run >>>> into >>>> this before? >>>> >>>> Thanks >>>> Greg Corradini >>> I suspect what's happening here is that you are presenting statements >>> you have made up programmatically, and the values you are trying to >>> insert include apostrophes that break the syntax of your SQL. However >>> there isn't really enough evidence to decide unless you are prepared to >>> show us the error traceback, possibly with a dump of the SQL statement >>> you are actually trying to execute. >>> >>> I apologize in advance if you are using parameterized queries (as you >>> should to avoid SQL injection vulnerabilities among other major >>> problems) but this message is typical of Access when it sees words it >>> can't parse. >>> > > Steve, > > As always, thanks for your consistent help on matters big and small. > > I've managed to solve the problem, although I'm scared b/c the bug is > still > > elusive. > > I dumped and deleted my separate Access DBs, created new ones and tried > > running the scripts on old data (that these scripts were able to digest > > successfully before) and new data (that they errored on to begin with). > > Everything works without me changing any code around. Hmm? > > > > I don't know much about Access or the JetEngine. Is it possible that > .mdbs > > can go corrupt if overused? This seems unlikely, but I'm dumbfounded. > > Greg: > > No, there are no known cases of a database getting "tired" :-) > > It sounds like a data dependency of some sort, but if the error has > "gone away" then I guess we no longer have anything to work with. This > is somewhat annoying, as I hate to see an error go untraced. > > Take it from me, it does look like a SQL error - *are* you building your > statements in the program, or are you using proper parameterization with > "?" in your statements where a parameter would go? > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC/Ltd http://www.holdenweb.com > Skype: holdenweb http://del.icio.us/steve.holden > Recent Ramblings http://holdenweb.blogspot.com > > -- > http://mail.python.org/mailman/listinfo/python-list > > Steve, Thanks for your reply. I used the proper parameterization with "?" in my SQL statements and still the problem persisted (although now it's gone). I do agree, an untraced error is definately annoying. Next time, I'll be more patient despite the workflow pileing up in front of me. Marc-Andre Lemburg did offer a couple pieces of advice that I'll follow up on and read about. He mentioneded the connection pooling and Access driver version I'm working with. Thanks again Greg Corradini -- View this message in context: http://www.nabble.com/Help-Understanding-mx.ODBC-Error-tf3602497.html#a10077031 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help Understanding mx.ODBC Error
Steve, As always, thanks for your consistent help on matters big and small. I've managed to solve the problem, although I'm scared b/c the bug is still elusive. I dumped and deleted my seperate Access DBs, created new ones and tried running the scripts on old data (that these scripts were able to digest successfully before) and new data (that they errored on to begin with). Everything works without me changing any code around. Hmm? I don't know much about Access or the JetEngine. Is it possible that .mdbs can go corrupt if overused? This seems unlikely, but I'm dumbfounded. Thanks again Greg Corradini Steve Holden wrote: > > Greg Corradini wrote: >> Hello All, >> A few weeks ago, I wrote two scripts using mx.ODBC on an Access DB. Among >> other things, both scripts create new tables, perform a query and then >> populate the tables with data in a dictionary that I've uploaded from >> elsewhere. These scripts have run hundreds of times in the last few weeks >> with no problems. >> >> But recently they continue to bail on the mycursor.execute('An SQL >> Statement') after the table has been created. I get the following error >> message: >> Traceback (most recent call last): >> File "C:\Documents and Settings\marv1shi\Desktop\Workspace\Existence >> Script\DBF Checker\Access_SQL.py", line 35, in ? >> curse.execute(sql) >> ProgrammingError: ('07001', -3010, '[Microsoft][ODBC Microsoft Access >> Driver] Too few parameters. Expected 4.', 4612) >> >> The real stinker, however, is that after it bails I can manually call >> mycursor.execute('An SQL Statement'), then call my insert statement in >> the >> Python Shell and it works fine. >> >> I just can't figure out how to reconcile this problem. Has anybody run >> into >> this before? >> >> Thanks >> Greg Corradini > > I suspect what's happening here is that you are presenting statements > you have made up programmatically, and the values you are trying to > insert include apostrophes that break the syntax of your SQL. However > there isn't really enough evidence to decide unless you are prepared to > show us the error traceback, possibly with a dump of the SQL statement > you are actually trying to execute. > > I apologize in advance if you are using parameterized queries (as you > should to avoid SQL injection vulnerabilities among other major > problems) but this message is typical of Access when it sees words it > can't parse. > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC/Ltd http://www.holdenweb.com > Skype: holdenweb http://del.icio.us/steve.holden > Recent Ramblings http://holdenweb.blogspot.com > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Help-Understanding-mx.ODBC-Error-tf3602497.html#a10065545 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help Understanding mx.ODBC Error
Thanks for you help kyosohma, Unfortunately, the data I'm using isn't chaning either. I've reused data that these scripts have successfully used before, but that won't work with them now. kyosohma wrote: > > On Apr 18, 1:36 pm, Greg Corradini <[EMAIL PROTECTED]> wrote: >> Hello All, >> A few weeks ago, I wrote two scripts using mx.ODBC on an Access DB. Among >> other things, both scripts create new tables, perform a query and then >> populate the tables with data in a dictionary that I've uploaded from >> elsewhere. These scripts have run hundreds of times in the last few weeks >> with no problems. >> >> But recently they continue to bail on the mycursor.execute('An SQL >> Statement') after the table has been created. I get the following error >> message: >> Traceback (most recent call last): >> File "C:\Documents and Settings\marv1shi\Desktop\Workspace\Existence >> Script\DBF Checker\Access_SQL.py", line 35, in ? >> curse.execute(sql) >> ProgrammingError: ('07001', -3010, '[Microsoft][ODBC Microsoft Access >> Driver] Too few parameters. Expected 4.', 4612) >> >> The real stinker, however, is that after it bails I can manually call >> mycursor.execute('An SQL Statement'), then call my insert statement in >> the >> Python Shell and it works fine. >> >> I just can't figure out how to reconcile this problem. Has anybody run >> into >> this before? >> >> Thanks >> Greg Corradini >> -- >> View this message in >> context:http://www.nabble.com/Help-Understanding-mx.ODBC-Error-tf3602497.html... >> Sent from the Python - python-list mailing list archive at Nabble.com. > > Normally too few parameters refers to the SQL statement not inserting > the proper number of items. An example would be to list 4 values and > only insert 3. See below for a pseudo-SQL statement: > > INSERT into someDB (id, name, address, state) VALUES (value1, value2, > value3) > > That should give the same error, I would think. You may need to check > if your SQL statement or the way your db is created has changed in > some way. > > Mike > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Help-Understanding-mx.ODBC-Error-tf3602497.html#a10065312 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Help Understanding mx.ODBC Error
Hello All, A few weeks ago, I wrote two scripts using mx.ODBC on an Access DB. Among other things, both scripts create new tables, perform a query and then populate the tables with data in a dictionary that I've uploaded from elsewhere. These scripts have run hundreds of times in the last few weeks with no problems. But recently they continue to bail on the mycursor.execute('An SQL Statement') after the table has been created. I get the following error message: Traceback (most recent call last): File "C:\Documents and Settings\marv1shi\Desktop\Workspace\Existence Script\DBF Checker\Access_SQL.py", line 35, in ? curse.execute(sql) ProgrammingError: ('07001', -3010, '[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 4.', 4612) The real stinker, however, is that after it bails I can manually call mycursor.execute('An SQL Statement'), then call my insert statement in the Python Shell and it works fine. I just can't figure out how to reconcile this problem. Has anybody run into this before? Thanks Greg Corradini -- View this message in context: http://www.nabble.com/Help-Understanding-mx.ODBC-Error-tf3602497.html#a10063746 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
mx.ODBC minor problem
Hello all, In a script i just wrote, my code calls a function createTables(), which checks for an existing table and then creates it, and then immediately calls selectSQL(), which selects from a different table and inserts on the table I just created (see below). However, I continue to get an Interface Error (see below) when i run it. And yet, if I allow the code to call createTables() and then manually call selectSQL() after a couple seconds, the thing works fine. In short, there's no mismatch in the number of parameters. Why would this be? I've never experienced this before. How can i restructure my code to resolve this problem? --- CODE --- def createTables(): # Drop AddScript Table try: curse.execute('Drop table ' +countyname+'ADD_SCRIPT_TABLE') conn.commit except: pass # Create AddScript Table curse.execute('Create table ' +countyname+'ADD_SCRIPT_TABLE'+ ' (TISCODE TEXT(12), STATUS TEXT(4))') conn.commit() def selectSQL(): sql = "Select TISCODE,STATUS from " +countyname+"0"+ " where STATUS = 'AS'" curse.execute(sql) a = curse.fetchall() curse.executemany('Insert into ' +countyname+'ADD_SCRIPT_TABLE'+ ' (TISCODE,STATUS) values (?,?)',x) conn.commit() --- ERROR --- InterfaceError: mismatch in number of parameters; expected 2, found none -- View this message in context: http://www.nabble.com/mx.ODBC-minor-problem-tf3569303.html#a9971678 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating Unique Dictionary Variables from List
Bruno, Your help is much appreciated. I will give this a try tomorrow morning and get back on how it works. Bruno Desthuilliers wrote: > > Greg Corradini a écrit : >> Hello All, >> I'm attempting to create multiple dictionaries at once, each with unique >> variable names. The number of dictionaries i need to create depends on >> the >> length of a list, which was returned from a previous function. >> The pseudo code for this problem would be: >> >> returnedlist = [x,y,z] >> count = 0 >> for i in returnedlist: >>if count < len(returnedlist): >># then create a dictionary (beginning with variable dic) for each >> i >> with a unique name such that >># my unique name would be dic + count >> >> Any ideas about this? > > Yes : use a dict to store your dicts: > > returnedlist = [x,y,z] > dicts = dict() > for num, item in enumerate(returnedlist): > dicts['dict%s' % num] = dict() > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Creating-Unique-Dictionary-Variables-from-List-tf3560643.html#a9947284 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Creating Unique Dictionary Variables from List
Hello All, I'm attempting to create multiple dictionaries at once, each with unique variable names. The number of dictionaries i need to create depends on the length of a list, which was returned from a previous function. The pseudo code for this problem would be: returnedlist = [x,y,z] count = 0 for i in returnedlist: if count < len(returnedlist): # then create a dictionary (beginning with variable dic) and add a unique ending such that # my final dictionary name would be dic + count for each i Any ideas about this? Greg -- View this message in context: http://www.nabble.com/Creating-Unique-Dictionary-Variables-from-List-tf3560471.html#a9943321 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Creating Unique Dictionary Variables from List
Hello All, I'm attempting to create multiple dictionaries at once, each with unique variable names. The number of dictionaries i need to create depends on the length of a list, which was returned from a previous function. The pseudo code for this problem would be: returnedlist = [x,y,z] count = 0 for i in returnedlist: if count < len(returnedlist): # then create a dictionary (beginning with variable dic) and add a unique ending such that # my final dictionary name would be dic + count for each i Any ideas about this? Greg -- View this message in context: http://www.nabble.com/Creating-Unique-Dictionary-Variables-from-List-tf3560470.html#a9943320 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Creating Unique Dictionary Variables from List
Hello All, I'm attempting to create multiple dictionaries at once, each with unique variable names. The number of dictionaries i need to create depends on the length of a list, which was returned from a previous function. The pseudo code for this problem would be: returnedlist = [x,y,z] count = 0 for i in returnedlist: if count < len(returnedlist): # then create a dictionary (beginning with variable dic) for each i with a unique name such that # my unique name would be dic + count Any ideas about this? Greg -- View this message in context: http://www.nabble.com/Creating-Unique-Dictionary-Variables-from-List-tf3560469.html#a9943317 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple mx.ODBC prob seeks simple answer
Thanks Steve, Once again your advice solved the problem Greg Steve Holden wrote: > > Greg Corradini wrote: >> Hello all, >> I'm having trouble inserting an SQL selection into a new MS Access table. >> I >> get a parameter error on my insert statement when I try this (see below >> for >> code and error msg). I'm not sure if 'insert' or 'update' is the route I >> should be taking. >> >> CODE: >> #Import Pythond Standard Library Modules >> import win32com.client, sys, os, string, copy, glob >> import mx.ODBC.Windows as odbc >> >> # Create the Geoprocessor Object >> gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") >> gp.overwriteoutput = 1 >> >> # Variables >> tempspace = "C:\Documents and Settings\corr1gre\Desktop\Workspace\DBFs & >> Shapefiles\TEST.mdb" >> workspace = string.replace(tempspace,"\\","/") >> worksheet1 = "Mower_I" >> worksheet2 = "Mower_II" >> >> #Conection to Access >> driv = 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+workspace >> conn = odbc.DriverConnect(driv) >> curse = conn.cursor() >> >> #Drop Tables if they already exist >> try: >> curse.execute('Drop table Table_I') >> curse.execute('Drop table Table_II') >> curse.execute('Drop table Checker') >> except: >> pass >> #Create a New Tables >> curse.execute('Create table Table_I (TISCODE TEXT(12), EXISTSIN >> TEXT(4),STATUS TEXT(3),NOTES TEXT(50))') >> curse.execute('Create table Table_II(TISCODE TEXT(12), EXISTSIN >> TEXT(4))') >> curse.execute('Create table Checker (TISCODE TEXT(12), EXISTSIN >> TEXT(4),STATUS TEXT(3),NOTES TEXT(50))') >> conn.commit() >> >> #Upload DBF 1 as a List of Tuples: Returns tuple as ('102150','BMP') >> sql = 'SELECT TISCODE,EXISTSIN from '+worksheet2 >> curse.execute(sql) >> x = curse.fetchall() >> >> #Put the fetched Data into Table_II >> for i in x: >> curse.execute('Insert into Table_II (TISCODE,EXISTSIN) values >> (%s,%s)'%(i[0],i[1])) >> conn.commit() >> conn.close() >> >> TRACEBACK ERROR MSG: >> Traceback (most recent call last): >> File "C:/Documents and >> Settings/corr1gre/Desktop/Workspace/Python/ArcGIS >> Python/ExistenceChecker and Update/Access Double Checker/Access_SQL.py", >> line 40, in ? >> curse.execute('Insert into Table_II (TISCODE,EXISTSIN) values >> (%s,%s)'%(i[0],i[1])) >> ProgrammingError: ('07001', -3010, '[Microsoft][ODBC Microsoft Access >> Driver] Too few parameters. Expected 1.', 4612) > > That error usually occurs when you use a name that isn't defined int he > database (typically I mistype a column name) - the JET engine then > thinks it's missing a value for some parameter. > > In your case it's because you aren't surrounding the string literal > value for TISCODE in your statement with the appropriate '' single > quotes. The engine thus parses it as a name, hence the assumption that a > parameter is missing. > > It's actually good that you have made this error, because it allows me > to expound yet again on the dangers of constructing your own SQL > statements instead of using parameterised statements. In the case of > mxODBC the correct parameter mark to use is a question mark. You should > then supply the data to be substituted for the parameter marks as a > tuple argument to the cursor's execute() method. > > So what you really need is: > > #Put the fetched Data into Table_II > for i in x: > curse.execute("""Insert into Table_II (TISCODE,EXISTSIN) > values (?, ?)""", i) > conn.commit() > conn.close() > > A couple of other points: > > 1. It would actually be better to put the commit() call outside the > loop. This is not only more efficient but it defines the whole set of > changes as a transaction. > > 2. It would be even more efficient not to use a loop at all but to use > the cursor's executemany() method to perform all inserts with a single > call as follows: > > #Put the fetched Data into Table_II > curse.executemany("""Insert into Table_II (TISCODE,EXISTSIN) > values (?, ?)""", x) > conn.commit() > conn.close() > > For more on using the DBI API, including something about the risks of > SQL injection vulnerabilities, take a look at the notes from my PyCon > tutorial at > >http://www.holdenweb.com/PyConTX2007/dbapi.tgz > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC/Ltd http://www.holdenweb.com > Skype: holdenweb http://del.icio.us/steve.holden > Recent Ramblings http://holdenweb.blogspot.com > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Simple-mx.ODBC-prob-seeks-simple-answer-tf3536661.html#a9873176 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Simple mx.ODBC prob seeks simple answer
Hello all, I'm having trouble inserting an SQL selection into a new MS Access table. I get a parameter error on my insert statement when I try this (see below for code and error msg). I'm not sure if 'insert' or 'update' is the route I should be taking. CODE: #Import Pythond Standard Library Modules import win32com.client, sys, os, string, copy, glob import mx.ODBC.Windows as odbc # Create the Geoprocessor Object gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") gp.overwriteoutput = 1 # Variables tempspace = "C:\Documents and Settings\corr1gre\Desktop\Workspace\DBFs & Shapefiles\TEST.mdb" workspace = string.replace(tempspace,"\\","/") worksheet1 = "Mower_I" worksheet2 = "Mower_II" #Conection to Access driv = 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+workspace conn = odbc.DriverConnect(driv) curse = conn.cursor() #Drop Tables if they already exist try: curse.execute('Drop table Table_I') curse.execute('Drop table Table_II') curse.execute('Drop table Checker') except: pass #Create a New Tables curse.execute('Create table Table_I (TISCODE TEXT(12), EXISTSIN TEXT(4),STATUS TEXT(3),NOTES TEXT(50))') curse.execute('Create table Table_II(TISCODE TEXT(12), EXISTSIN TEXT(4))') curse.execute('Create table Checker (TISCODE TEXT(12), EXISTSIN TEXT(4),STATUS TEXT(3),NOTES TEXT(50))') conn.commit() #Upload DBF 1 as a List of Tuples: Returns tuple as ('102150','BMP') sql = 'SELECT TISCODE,EXISTSIN from '+worksheet2 curse.execute(sql) x = curse.fetchall() #Put the fetched Data into Table_II for i in x: curse.execute('Insert into Table_II (TISCODE,EXISTSIN) values (%s,%s)'%(i[0],i[1])) conn.commit() conn.close() TRACEBACK ERROR MSG: Traceback (most recent call last): File "C:/Documents and Settings/corr1gre/Desktop/Workspace/Python/ArcGIS Python/ExistenceChecker and Update/Access Double Checker/Access_SQL.py", line 40, in ? curse.execute('Insert into Table_II (TISCODE,EXISTSIN) values (%s,%s)'%(i[0],i[1])) ProgrammingError: ('07001', -3010, '[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.', 4612) -- View this message in context: http://www.nabble.com/Simple-mx.ODBC-prob-seeks-simple-answer-tf3536661.html#a9871804 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble w/ 'create table' sql on mx.ODBC
Thanks for responding everyone, I never received a traceback, the program did complete without changes to the database. However, the conn.commit() did work (Thanks Steve). I should've know that was the problem (or at least tried), b/c I saw so many posts about a similar problem with Update and Insert. Thanks to all Greg Corradini Steve Holden wrote: > > Greg Corradini wrote: >> Hello, >> Lately I've been using the mx.ODBC module to query Access (mdb) tables. >> For >> the life of me, I can't get the 'create table' sql command to work. I use >> this command in Oracle and I've seen other mx.ODBC users weave into their >> scripts for Access. But I still can't get this simple test run below to >> work >> (ignore the geoprocessor object for ArcGIS): >> >> #Import Python Standard Library Modules >> import win32com.client, sys, os, string, copy, glob >> import mx.ODBC.Windows as odbc >> >> # Create the Geoprocessor Object >> gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") >> gp.overwriteoutput = 1 >> >> # Variables >> tempspace = "C:\Documents and Settings\corr1gre\Desktop\Workspace\DBFs & >> Shapefiles\TEST.mdb" >> workspace = string.replace(tempspace,"\\","/") >> >> #Conection to Access >> driv = 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+workspace >> conn = odbc.DriverConnect(driv) >> curse = conn.cursor() >> >> #Upload Tbl 1 as a List of Tuples >> curse.execute('SELECT TISCODE,EXISTSIN,STATUS,NOTES from Mower_I') >> x = curse.fetchall() >> >> #Create New Table >> curse.execute('Create table TEST (TISCODE Integer)') >> curse.close() >> conn.close() >> del gp > > So what happens? Do you see a traceback, or does the program complete > without any apparent change to the database? > > It might be because Access doesn't automatically commit DDL changes like > some other databases do. Try adding a conn.commit() before your > conn.close(). > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC/Ltd http://www.holdenweb.com > Skype: holdenweb http://del.icio.us/steve.holden > Recent Ramblings http://holdenweb.blogspot.com > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Trouble-w--%27create-table%27-sql-on-mx.ODBC-tf3532982.html#a9863381 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Trouble w/ 'create table' sql on mx.ODBC
Hello, Lately I've been using the mx.ODBC module to query Access (mdb) tables. For the life of me, I can't get the 'create table' sql command to work. I use this command in Oracle and I've seen other mx.ODBC users weave into their scripts for Access. But I still can't get this simple test run below to work (ignore the geoprocessor object for ArcGIS): #Import Python Standard Library Modules import win32com.client, sys, os, string, copy, glob import mx.ODBC.Windows as odbc # Create the Geoprocessor Object gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") gp.overwriteoutput = 1 # Variables tempspace = "C:\Documents and Settings\corr1gre\Desktop\Workspace\DBFs & Shapefiles\TEST.mdb" workspace = string.replace(tempspace,"\\","/") #Conection to Access driv = 'DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+workspace conn = odbc.DriverConnect(driv) curse = conn.cursor() #Upload Tbl 1 as a List of Tuples curse.execute('SELECT TISCODE,EXISTSIN,STATUS,NOTES from Mower_I') x = curse.fetchall() #Create New Table curse.execute('Create table TEST (TISCODE Integer)') curse.close() conn.close() del gp -- View this message in context: http://www.nabble.com/Trouble-w--%27create-table%27-sql-on-mx.ODBC-tf3532982.html#a9860747 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list