Insert statement cx_Oracle - cx-oracle

I am new to cx_Oracle and working on a project using Python3, and getting some errors. Here is my code:
uemail="jack#gmail.com"
uname="Jack"
upassword="asdasd"
cursInsert=connection.cursor()
insert_stat="insert into users(email,name,pass,last_login) values (:uemail,:uname,:upassword,NULL)"
cursInsert.execute(insert_stat)
connection.commit()
cursInsert.close()
Here is the error message that I get: not all variables bound
Thanks

You have to pass values to the bind variables for oracle like this
cursInsert.execute(insert_stat, uemail=uemail, uname=uname, upassword=upassword)

Related

PyMySQL escaping args does not work for database names

To prevent SQL injections I do not use f-Strings or the format() for queries with dynamic content. This works fine for alle CRUD operations on tables. But when I try to create a test database with it, it does not work. My code is simple:
def test_create_and_load_dump(connection):
with connection.cursor() as cursor:
cursor.execute("CREATE OR REPLACE DATABASE %s", ("foo",))
connection is just the normal pymysql.Connection.
This code raises the following error:
pymysql.err.ProgrammingError: (1064, "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 ''foo'' at line 1")
The raw query after the execution of mogrify() from PyMySQL is
'CREATE OR REPLACE DATABASE \'foo\''
So it escapes the ' characters which causes the error above.
Is this a bug in the PyMySQL library or am I doing something wrong here?

Issue on importing Dataframe into SQL Server with d6tstack.utils library of Python3

I am having problems with the function d6tstack.utils.pd_to_mssql() when I want to import the Dataframe into Microsoft SQL Server database with Python3. The name of SQL Table is fxxProduktKatalogDE. I found that the name in function should be written lowercase and so I did. But I get the error as the Table does not exists. The table is there in database. I also tried to write in the table name the name exactly as in database but the same error happens.
Here the Code and the error
Code
Error
Thank you in advance !

Errors when attempting to update multiple column values in a MySQL DB using multiple WHERE clause values

I'm currently getting an error when attempting to update two columns of my MySQL database using mysql.connector and python 3.6. When I execute the command below I get:
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 'order='1' WHERE (match_id='2051673' AND gametime=80 AND event_name='Pass')' at line 1
But, as far as I can tell, my command is perfectly legit. What am I doing incorrectly? Thanks!
for item in pass_list:
query = """UPDATE events SET event_key=%s AND order=%s
WHERE (match_id=%s AND gametime=%s AND event_name=%s)"""
values = (item[0],item[7],item[1],item[2],item[3])
cur.execute(query, values)
conn.commit()
conn.close()
For good or bad, order is a SQL keyword. You can put backticks around it:
`order`

cx_Oracle returning zero rows

I am new to connecting to oracle db (version 19.3) through python 3.6. I am not getting any rows in return. Please tell me what am I missing here?
I think all connection is set up correctly because it's not showing any connection error or invalid password error. Tried using fetchall(), fetchmany(), rowcount etc. everything is returning zero. I tried printing the cursor object itself, which is working. I ran the query in my DB. I have Oracle DB 19.3 installed locally, using Oracle SQL developer for running SQL. Anything else I need to install?
import cx_Oracle
conn = cx_Oracle.connect("username", "password", "localhost/orcl")
cur = conn.cursor()
cur.execute('select * from emp')
for line in cur:
print(line)
cur.close()
conn.close()
After running
delete from emp;
your python program will display zero rows, as you report.
You may wish to INSERT one or more rows before running it.
You may also find the interface offered by sqlalchemy to be more convenient.
It offers app portability across Oracle and other DB backends.
Cf https://developer.oracle.com/dsl/prez-python-queries.html

AssertionError when using self-defined nested list in Pyspc

I installed pyspc and run on Jupyter Notebook successfully when using original samples.
But when I tried introducing a self defined nested list and an error message showed up.
pyspc library: https://github.com/carlosqsilva/pyspc
from pyspc import*
import numpy
abc=[[2,3,4],[4,5.6],[1,4,5],[3,4,4],[4,5,6]]
a=spc(abc)+xbar_rbar()+rules()+rbar()
print(a)
error message for AssertionError
Thank you for advise where went wrong and how to fix it.
Check the data you have accidentally used the . instead of , for value [4,5.6], second element of the list.
Here is the corrected data
abc=[[2,3,4],[4,5,6],[1,4,5],[3,4,4],[4,5,6]]
Hope this will help.

Resources