Traceback (most recent call last):
File "****", line 17, in module
cur.execute("CREATE TABLE `Project1`(`Id` INT PRIMARY KEY NOT NULL ,`TERM` VARCHAR(25) CHARACTER SET utf8 NOT NULL, `TYPE1` VARCHAR(25) CHARACTER SET utf8 NOT NULL, `ACTION` VARCHAR(30) CHARACTER SET utf8 NOT NULL, `CERTAINITY` DOUBLE(3) NOT NULL");
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
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 syntax to use near ') NOT NULL' at line 1")
line 1: import mysqldb as mdb
after rectifying the double problem,
I got a similar error, with the last sentence changed as
_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 syntax to use near '' at line 1")
the line to create tables was modified to
CREATE TABLE Project1(Id INT PRIMARY KEY NOT NULL ,Term VARCHAR(25) CHARACTER SET utf8 NOT NULL, Type1 VARCHAR(25) CHARACTER SET utf8 NOT NULL, Action VARCHAR(30) CHARACTER SET utf8 NOT NULL, Certainity DOUBLE(4,3) NOT NULL)
NEW PROBLEM,
I changed 'Certainity' to string
File "/home/ankitaprasad/Ontology Project3/Stanford.py", line 57, in <module>
cur.execute("""INSERT INT0 Project1(Term, Type1, Action, Certainity) VALUES (%s,%s,%s,%s)""",(term,type1,action,ab));
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
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 syntax to use near 'Project1(Term, Type1, Action, Certainity) VALUES ('','','','0')' at line 1")
[Finished in 1.2s with exit code 1]
here ab=str(mod)
First off, your entire create statement formatted into this:
CREATE TABLE `Project1` (
`Id` INT PRIMARY KEY NOT NULL,
`TERM` VARCHAR(25) CHARACTER SET utf8 NOT NULL,
`TYPE1` VARCHAR(25) CHARACTER SET utf8 NOT NULL,
`ACTION` VARCHAR(30) CHARACTER SET utf8 NOT NULL,
`CERTAINITY` DOUBLE(3) NOT NULL
See where you are missing the closing parentheses? Fixing that, you still have a problem as DOUBLE require two arguments, not one, so that is a syntax error for MySQL. Please read the documentation and carefully look at what you wrote before asking questions and it will save you a lot of time, especially shortly before a deadline.
Related
I have an operational SQLite3 error. Previously when I have had this error it has been about brackets or something like that but I can't see what is causing the problem here.
//declared the table:
c.execute("CREATE TABLE IF NOT EXISTS ids (appointmentID, clientID, dentistID)")
//I have a program here to take the inputs
c.execute('''INSERT INTO ids (appointmentID, clientID, dentistID) VALUES (?,?,?),''', (appointmentID, clientID, dentistID))
Here is the full error traceback:
// this is the error
Traceback (most recent call last):
File "C:/Users/barna/OneDrive/Documents/A- Level/NEA/fixing `error.py`", line 124, in <module>
login()
File "C:/Users/barna/OneDrive/Documents/A- Level/NEA/fixing `error.py`", line 33, in login
checkIds(foundID)
File "C:/Users/barna/OneDrive/Documents/A- Level/NEA/fixing `error.py`", line 84, in checkIds
c.execute("INSERT INTO IDs (appointmentID, clientID, dentistID) VALUES (?,?,?),", (appointmentID, clientID, dentistID))
sqlite3.OperationalError: incomplete input
I have a problem inserting data into my database table. I'm using Python and MariaDB. Connection to database is open and tested, I'm able to query the database, but I can't nail the insert syntax. I've found two ways, but neither work.
insert = (
"INSERT INTO ksiazka (ISBN, tytul, autor, rok_wydania, ilosc stron)"
"VALUES (%s,%s,%s,%s,%s)"
)
dane = (ISBN, tytul, autor, rok_wydania, ilosc_stron)
cursor.execute(insert, dane)
or this way:
cursor.execute("INSERT INTO ksiazka (ISBN, tytul, autor, rok_wydania, ilosc stron) VALUES (%s,%s,%s,%s,%s)", (ISBN, tytul, autor, rok_wydania, ilosc_stron))
When executing I get this error:
Traceback (most recent call last): File
"C:\Users\jakub\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\connection_cext.py",
line 377, in cmd_query
raw_as_string=raw_as_string)
_mysql_connector.MySQLInterfaceError: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server
version for the right syntax to use near 'stron)VALUES
('12345678','wertvfdg','3','1243','213')' at line 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:/Users/jakub/PycharmProjects/biblioteka/sql_connector.py", line 57,
in
cursor.execute(insert, dane) File "C:\Users\jakub\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\cursor_cext.py",
line 264, in execute
raw_as_string=self._raw_as_string) File "C:\Users\jakub\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\connection_cext.py",
line 380, in cmd_query
sqlstate=exc.sqlstate) mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual
that corresponds to your MariaDB server version for the right syntax
to use near 'stron)VALUES ('12345678','wertvfdg','3','1243','213')' at
line 1
If your column name has a space in it, then it needs special handling and you must escape it:
INSERT INTO ksiazka (ISBN, tytul, autor, rok_wydania, `ilosc stron`) ...
This is why spaces in column names are annoying and should be avoided.
So I've got a .sql file that I want to build over to a .db file for sqllite3, but I'm getting a
sqlite3.OperationalError: near "ENGINE": syntax error
Any ideas why? Any help is appreciated.
import sqlite3
conn = sqlite3.connect('newdatabase.db')
f = open('olddatabase.sql','r')
sql = f.read()
conn.executescript(sql)
conn.close()
OUTPUT:
Traceback (most recent call last):
File "deleteme.py", line 6, in
conn.executescript(sql)
sqlite3.OperationalError: near "ENGINE": syntax error
(program exited with code: 1)
Divining based on ENGINE, you have a .sql file dumped by MySQL (CREATE TABLE ... ENGINE=InnoDB or similar), so it contains MySQL-specific extensions.
You'll have to either edit the .sql file to conform to SQLite's standards or figure out a way to convert it automatically to a more standard sequence of SQL instructions.
Here is the error:
gutschy#kiste:~/pizza/pizza_daten$ python datenimport3.py
Traceback (most recent call last):
File "datenimport3.py", line 20, in <module>
")
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
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 syntax to use near ''Adressliste_forum1_v4.csv' INTO TABLE pizzeria_table FIE' at line 1")
gutschy#kiste:~/pizza/pizza_daten$
Here the datenimport3.py
#!/usr/bin/python
#-*- coding: utf-8 -*-
import MySQLdb as mdb
con = mdb.connect('localhost', 'user', 'passw', 'pizzadb2');
with con:
cur = con.cursor(mdb.cursors.DictCursor)
cur.execute(" 'Adressliste_forum1_v4.csv'\
INTO TABLE pizzeria_table \
FIELDS TERMINATED BY ',' \
ENCLOSED BY '\"' \
LINES TERMINATED BY '\\n' \
IGNORE 1 LINES \
(laden_name, vorwahl, telenr1, strasse, hausnr, \
ort, linkname1, linkname2, linkname3, forum_link, \
link2, link3, banner) \
")
Four month ago it works all fine, than I killed my debian 7 and now I'm on to bring it in the same way like before. I've add the last field "banner" new but I've done noting more.
You can sort through all that traceback chaff by looking for this:
...for the right syntax to use near ''Adressliste_forum1_v4.csv' INTO ...
On a 1064 error, MySQL presents, right after "use near", your statement starting with the place where its parse error was found.
Now, should not your statement start with
LOAD DATA INFILE 'Adressliste_forum1_v4.csv' INTO ...
?
In order to delete the table named cars I created in python-mysql , I do
import MySQLdb as mdb
con = mdb.connect('localhost', 'priceapi', 'data', 'carpricedb');
cur = con.cursor()
cur.execute("DELETE FROM cars");
con.commit()
con.close()
But I get an error like this
Traceback (most recent call last):
File "delete.py", line 4, in <module>
cur.execute("DELETE FROM cars");
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1205, 'Lock wait timeout exceeded; try restarting transaction')
My Table only has 78 rows. I also tried truncating the table. The result is the same.
I tried doing it directly in mysql , but then it doesnt execute the command and I had to kill it using Control+C. I searched a lot for the last 1 hour, but could not find the solution .
Any help please ?
Delete is very very very very slow SQL operation and i guess that the table is huge so it takes a lot of time to finish. It's best to drop and recreate a table if you want it clear (truncate is a 2nd best option).
It is also possible that some query is locking your table, you can clear that lock off by stopping and starting mysql again (or by finding which query is doing that and kill it).