Questions tagged [python-db-api]

Questions about how to use the Python Database API Specification 2.0 -- PEP 249. Do include details about your database library

This API has been defined to encourage similarity between the Python modules that are used to access databases. By doing this, we hope to achieve a consistency leading to more easily understood modules, code that is generally more portable across databases, and a broader reach of database connectivity from Python.

See: https://www.python.org/dev/peps/pep-0249/

134 questions
0
votes
2 answers

Python DBAPI time out for connections?

I was attempting to test for connection failure, and unfortunately it's not failing if the IP address of the host is fire walled. This is the code: def get_connection(self, conn_data): rtu, hst, prt, usr, pwd, db = conn_data try: …
Rob
  • 2,511
  • 2
  • 20
  • 31
0
votes
1 answer

Inserting multiple rows using psycopg2

According to psycopg2: insert multiple rows with one query, it is much more efficient to use psycopg2's execute instead of executemany . Can others confirm? The above StackOverflow question suggests using mogrify for creating statements of the…
ChaimKut
  • 2,759
  • 3
  • 38
  • 64
0
votes
1 answer

Why does Python's Sqlite3 module correctly parse the first instance of this parameter substitution and afterwards not? Caching?

I have a Sqlite3 table that has a LastUpdated column containing UTC datetimes formatted as "2013-12-24 07:11:21", and all the rows int that table were updated 2 days ago. I want to write a SELECT statement to return only rows that haven't been…
Jeff Widman
  • 22,014
  • 12
  • 72
  • 88
0
votes
1 answer

Choosing python client lib for Cassandra

I have worked with Pycassa before and wrote a wrapper to use batch mutation & connection pooling etc. But http://wiki.apache.org/cassandra/ClientOptions recommends now to use CQL 3 based api because Thrift based api (Pycassa) will be supported for…
NullException
  • 4,232
  • 8
  • 24
  • 44
0
votes
2 answers

MySQL driver issues with INFORMATION_SCHEMA?

I'm trying out the Concurrence framework for Stackless Python. It includes a MySQL driver and when running some code that previously ran fine with MySQLdb it fails. What I am doing: Connecting to the MySQL database using dbapi with…
mthurlin
  • 26,247
  • 4
  • 39
  • 46
0
votes
1 answer

how will Python DB-API read json format data into an existing database?

If we have a json format data file which stores all of our database data content, such as table name, row, and column, etc content, how can we use DB-API object to insert/update/delete data from json file into database, such as sqlite, mysql, etc. …
user1342336
  • 967
  • 2
  • 16
  • 28
0
votes
2 answers

Update multiple rows with unique key

I want to update multiple rows identified by unique key without inserting new rows. Below is my table: CREATE TABLE `insert_update_ignore` ( `obj_id` int(11) NOT NULL, `obj_type` tinyint(4) NOT NULL, `value` int(11) DEFAULT '-1', …
schemacs
  • 2,783
  • 8
  • 35
  • 53
0
votes
1 answer

What does an SQLite 'Error binding parameter 0: probably unsupported type' mean?

I have Python code: cursor.execute('INSERT INTO users (email, password, password_hint, state, last_saved) VALUES (?, ?, ?, ?, DATETIME("now"));', ((get_cgi('email'),), (password,), (get_cgi('password_hint'),), (get_cgi('current'),))) This is…
Christos Hayward
  • 5,777
  • 17
  • 58
  • 113
0
votes
3 answers

PyMySQL error/exception on (file) data load to remote MySQL instance

I am using PyMySQL-0.5.0 and facing an obscure'ish error/exception when loading data from a file to a remote MySQL instance. Upon executing a 'load data local infile ...' statement, I am seeing an exception that says: The used command is not allowed…
decimus phostle
  • 1,040
  • 2
  • 13
  • 28
0
votes
2 answers

Escaping MySQL reserved words with Python dbapi

I am looking for a nice "pythonic" and "SQL-Injection-free" solution for a problem with reserved words in MySQL. I have the following code: alter_sql = 'ALTER TABLE %s ADD COLUMN %s TEXT' cursor.execute(alter_sql, sql_params) The problem…
kijasek
  • 33
  • 4
-1
votes
1 answer

Can't catch connection error clickhouse-driver db api

I'm trying to catch a connection error when connecting to kx using the clickhouse-driver db api in python. But for some reason, the try: block passes without errors, and I don't get exception def __enter__(self): try: self.connector =…
FeoJun
  • 103
  • 1
  • 14
-1
votes
1 answer

Microsoft Access database engine cannot find the input table or query

I'm trying to establish connection with Microsoft Office and to run a query but it is showing error Here is my code: import pyodbc conn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb,…
Rafey
  • 1
  • 2
-2
votes
2 answers

Python SQLite query returns None

The following SQLite query returns 3: SELECT MAX(depth) FROM mpitree WHERE child = 2 But this code evaluates to None: def ancestors_depth(self): self.cursor.execute("SELECT MAX(depth) FROM mpitree WHERE child = 2"); return…
N.J.
  • 37
  • 3
  • 8
-5
votes
1 answer

Table input parameters and scalar output parameters

I have the following table and the following stored procedure (simplified to the bare basics needed to demonstrate the problem): CREATE TABLE T(C INT); CREATE PROCEDURE PROC(IN T TABLE(C INT), OUT X INT) AS BEGIN X = 5; END; From HANA Studio, I can…
user2357112
  • 260,549
  • 28
  • 431
  • 505
1 2 3
8
9