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
Related
My first SQL database Im using sqlite3 in idle on linux. Everything is working fine but I want my table to display in an easier to read format in the terminal. Been reading about dot commands eg .mode column or .headers on but not sure were to put it in my code, I think this is the closest:
def veiw_outstanding_job():
cursorObj = con.cursor()
cursorObj.execute('.mode column\nSELECT * FROM '+ VesselName + ' WHERE State = "outstanding" ')
rows = cursorObj.fetchall()
for row in rows:
print(row)
menu()
but i get this error
Traceback (most recent call last):
File "/usr/lib/python3.8/idlelib/run.py", line 559, in runcode
exec(code,self.locals)
File "/home/mike/Documents/Maintenance Manager/Maintenanceanager.py", line 238, in <module>
menu()
File "/home/mike/Documents/Maintenance Manager/Maintenance Manager.py", line 27, in menu
veiw_job(con)
File "/home/mike/Documents/Maintenance Manager/Maintenance Manager.py", line 54, in veiw_job
cursorObj.execute('.mode column\nSELECT * FROM '+ VesselName) sqlite3.OperationalError: near ".":
syntax error
(also asked on database admin stackexchange and got sent here)
hi~ I want to access pgsql through psycopg2, but an error is reported.I use the same command and have no problem in the pgsql.
import psycopg2
connect = psycopg2.connect(database='xxx',
user='xxx',
password='xxx',
host='xxxx',
port=1521)
cursor=connect.cursor()
cursor.execute('SELECT version()')
rows = cursor.fetchall()
for row in rows:
print(row)
Traceback (most recent call last):
File "C:/Users/z30007746/PycharmProjects/untitled3/pt_test.py", line 14, in <module>
cursor.execute('SELECT version()')
psycopg2.errors.SyntaxError: syntax error at end of input
QUERY: DECLARE
BEGIN
CONTEXT: FUNCTION: plspl_anon_func
LINE 1 FROM "CREATE": BEGIN
I am trying to connect to oracle database and execute a query using cx_Oracle in python with following code
import cx_Oracle
mobileNumber='1234567890'
dbHost='some_value'
dbPortNumber='some_value'
dbUsername='some_value'
dbPasswd='some_value'
dsn_tns = cx_Oracle.makedsn(dbHost, dbPortNumber, service_name='ORCL')
conn = cx_Oracle.connect(user=dbUsername, password=dbPasswd, dsn=dsn_tns)
cur=conn.cursor()
query='insert into table_name values ((select max(ID)+1 from table_name),"sms","'+ mobileNumber + '")'
cur.execute(query)
res=cur.fetchall()
print (res)
But I am getting following exception when running this code
Traceback (most recent call last):
File "script.py", line 16, in <module>
result=cur.fetchall()
cx_Oracle.InterfaceError: not a query
When printing the value of variable query I am getting following
insert into table_name values ((select max(ID)+1 from table_name),"sms","1234567890")
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.
I'm trying update a row in a table but I'm getting an Argument Error.
Here is the code:
inventory_host = InventoryHost(ipv4_addr=ipv4, ipv6_addr=ipv6, macaddr=mac, host_name=name)
try:
session.add(inventory_host)
session.commit()
except sqlalchemy.exc.IntegrityError:
session.execute(update(inventory_host))
session.commit()
session.close()
This is the error I'm getting:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "perception.py", line 77, in <module>
main()
File "perception.py", line 66, in main
modules.nmap_parser.parse_nmap_xml(nmap_xml)
File "/Users/arozar/Documents/Scripts_Code/Python-Projects/perception/modules/nmap_parser.py", line 128, in parse_nmap_xml
session.execute(update(inventory_host))
File "<string>", line 2, in update
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/sqlalchemy/sql/dml.py", line 668, in __init__
ValuesBase.__init__(self, table, values, prefixes)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/sqlalchemy/sql/dml.py", line 183, in __init__
self.table = _interpret_as_from(table)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/sqlalchemy/sql/selectable.py", line 41, in _interpret_as_from
raise exc.ArgumentError("FROM expression expected")
sqlalchemy.exc.ArgumentError: FROM expression expected
The session.add(inventory_host) works for new hosts in the inventory_host table, but as soon as I try and update the row using session.execute(update(inventory_host)) I get the error.
update takes a table name as its first arg, not an instance of your table class. What value(s) do you want to update? If you wanted to update the host_name, for example, you might do this instead:
from sqlalchemy import update
# Ideally, just use your primary key(s) in your where clause; I'm not sure what they are
stmt = (update(InventoryHost).where(ipv4_addr=ipv4, ipv6_addr=ipv6, macaddr=mac)
.values(host_name=name) # updates the host_name, for example
session.execute(stmt)
...