Pysqlite2.dbapi2.operationalerror Near Syntax Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this sqlite3.operationalerror syntax error site About Us Learn more about Stack Overflow the company Business Learn more sqlite3.operationalerror no such table about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x
Sqlite3.operationalerror Unable To Open Database File
Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up sqlite3 “OperationalError:
Sqlite3.operationalerror Database Is Locked
near ”(“: syntax error” python up vote 2 down vote favorite simply put i am trying to make a sql database table and input data into it. I have it working in a simpler way, but when I put it into my script it results in this error. I'm hoping its something simple I missed. Any help/advice would be greatly appreciated. conn = sqlite3.connect('Data1.db') sqlite3 operationalerror near text syntax error c = conn.cursor() # Create table c.execute('''CREATE TABLE Data_Output6 (date text, output6MV real)''') Averages_norm = [] for i, x in enumerate(Averages): Averages_norm.append(x*output_factor) c.execute("INSERT INTO Data_Output6 VALUES (%r,%r)" %(xdates[i],Averages_norm[-1])) conn.commit() results in the error: 57 for i, x in enumerate(Averages): 58 Averages_norm.append(x*output_factor) ---> 59 c.execute("INSERT INTO Data_Output6 VALUES (%r,%r)"%(xdates[i],Averages_norm[-1])) 60 conn.commit() 61 OperationalError: near "(": syntax error python sqlite3 share|improve this question edited May 15 '15 at 11:01 Martijn Pieters♦ 502k7513181473 asked May 15 '15 at 10:59 Ciaran 86111 So what data do you have in xdates? –Martijn Pieters♦ May 15 '15 at 11:02 3 Also, why are you using string interpolation instead of SQL parameters? –Martijn Pieters♦ May 15 '15 at 11:02 1 Try printing the statement before executing it. I'm sure you'll immediately spot the error. –Andrea Corbellini May 15 '15 at 11:57 2 You're inviting Booby Tables to tea... bobby-tables.com –LexyStardust May 15 '15 at 12:58 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote accepted Simply put, let the DB API do that formatting: c.execute("INSERT INTO Data_Output6 VALUES (?, ?)", (xdates[i], Averages_norm[-1])) And refer to the documentation https://docs.python.org/2/lib
here for a quick overview of the site Help Center Detailed answers to
Python Sqlite3 Insert Example
any questions you might have Meta Discuss the workings and policies near syntax error sqlite3 ios of this site About Us Learn more about Stack Overflow the company Business Learn more python sqlite3 tutorial about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack http://stackoverflow.com/questions/30257826/sqlite3-operationalerror-near-syntax-error-python Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up sqlite3.OperationalError: near “,”: syntax error [closed] up vote 0 down vote favorite Update 1: The other line works (Thanks for the help!). Now i tried to run the http://stackoverflow.com/questions/22870315/sqlite3-operationalerror-near-syntax-error following, and this wont work either, i get an error for line 13: sqlite3.OperationalError: near ",": syntax error the code is as follows: cur.execute("CREATE TABLE Progress(Id INTEGER PRIMARY, Username STRING, Topic1 STRING, Topic2 STRING, Topic3 STRING, Topic4 STRING, 1Result STRING, 2Result STRING, 3Result STRING, 4Result STRING, TResut STRING, TCorrect INTEGER, TWrong INTEGER, TAttempted INTEGER)") cur.exectue("INSERT INTO Progress VALUES(1, 'Admin', 'Algebra', 'Number', 'Shape, Space and Measures', 'Handling Data', '100%', '100%', '100%', '100%', '100%', '10', '0', '10')") I have created an SQL Table as shown below and am trying to input some data into the table, but i keep getting the following error: sqlite3.OperationalError: near "1": syntax error con = lite.connect('Records.db') with con: cur = con.cursor() cur.execute("CREATE TABLE Questions(Id INTEGER PRIMARY KEY, Question STRING, Answer STRING, Mark INTEGER, Topic STRING, Incorrect STRING, QType STRING)") cur.execute("INSERT INTO Questions(1, 'What is 2/3 of 6?', '4', '1', 'Fractions', 'None', 'Numerical')") python sql sqlite share|improve this question edited Ap
GoogleВойтиСкрытые поляПоиск групп или сообщений
SQL generated.On Monday, September 19, 2016 at 11:53:49 AM UTC-4, Peter wrote:Thanks for your response Anthony!I have obviously misunderstood a reference I read somewhere saying that reference fields were given special attributes and gave an example something like db.fieldname.name I assumed the trailing .name came from the referenced table attributes.So I have modified the code ...def generate_inv_details(): session.inv_details = [] session.inv_total = 0 today = datetime.date.today() query = db( (db.task.person.belongs( session.company_persons)) & (db.task.start_time <= today ) & (db.task.charge_to == 'COMPANY' ) & (db.task.task_status == 'BILLABLE') & (db.person.id==db.task.person)) rows=db(query).select( db.task.person, db.person.name, db.task.title, db.task.start_time, db.task.duration, db.task.task_type, db.task.task_status, db.task.charge_to, db.task.charge, db.task.payment_status ) session.inv_details=rows for row in session.inv_details: session.inv_total += row.task.charge added the join (I hope correctly) in the query used full "tablename.fieldname" format to reference the person.name in the select statement removed the newline slashesThe relevant table excerpts...db.define_table('person', Field( 'name' , requires=IS_NOT_EMPTY() , comment="*"), Field( 'status' , requires=IS_IN_SET(PERSON_STATUS) , comment="*") , Field( 'type' , requires=IS_IN_SET(PERSON_TYPES) , comment="*") , Field( 'company' , 'reference company' , comment="*"), Field( 'role' , 'string' , comment='for CONTACTS not CLIENTS'), Field( 'address' , comment="Use ',' to seperate address lines"), Field( 'mobile_phone' , label='Mobile' , requires=IS_EMPTY_OR(is_phone), comment="Can use '-' to separate prefix for clarity" ), Field( 'office_phone' , label='Office' , requires=IS_EMPTY_OR(is_phone), comment="Can use '-' to separ