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
1
vote
0 answers

Reveal the meaning of DBAPI error message dictionary keys

For a few months Ive been working with pg8000 and have noticed when it throws an error like dbapi.ProgrammingError, the message is followed by a dictionary with some keys and values. Where can I find a reference to explain the meaning of the…
dannylee8
  • 505
  • 7
  • 17
1
vote
4 answers

IBM Db2 : An unexpected token "as" was found following "SELECT test_score " (SQL0104N)

I am now having trouble with IBM Db2 using queries. I have a code below: test_score_distribution = %sql SELECT test_score as "Test Score", count(*) as "Frequency" from INTERNATIONAL_STUDENT_TEST_SCORES GROUP BY…
Le Hoang Phuc
  • 11
  • 1
  • 2
1
vote
1 answer

DB-API x database module

What is a DB-API (Python) and what is a database module and how do they interact ? I have a TCC project and I need to understand the difference and the purpose of these terms. I thought DB-API was, for example, a driver like psycopg2 but psycopg2 is…
user14522494
1
vote
0 answers

What is actual SQL produced by cursor.execute() through python dbapi 2.0?

I'll admit it. I've been doing this for literally decades: sql = 'select * from whatever where key = "%s"' % ('thing') cursor.execute(sql) One big reason is that print(sql) tells me something useful. Whereas this: sql = 'select * from whatever…
drysdam
  • 8,341
  • 1
  • 20
  • 23
1
vote
1 answer

Is there a way to select schema in python hdbcli dbapi?

According to documentation, parameters needed to connect to HANA database are host, port, user and password. from hdbcli import dbapi conn = dbapi.connect( address="", port=3MM, user="", …
1
vote
1 answer

How to determine if Python DB-API connection object is of a certain DBMS (e.g., PostgreSQL, MySQL)

Let the driver be a DB-API driver (e.g., psycopg2, pymysql) and you can get the connection object via connnection = driver.connect(...). How do I check what kind of DBMS the connection object is connected to: (1) At best the DBMS name or (2) the…
Keto
  • 1,470
  • 1
  • 12
  • 25
1
vote
1 answer

Implementing Python DB-API

I'm trying to implement the python DB-API for a small "database" that we built internally. This database does not expose an ODBC interface (or JDBC for that matter). My goal is to create a sqlalchemy for this so that I can use it with an application…
NEO
  • 1,961
  • 8
  • 34
  • 53
1
vote
1 answer

snowflake python connector - Time to make database connection

Python code is taking around 2-3 secs to make the snowflake database connection. Is it expected behaviour ? OR are there any parameters which will speed up connection time. Here is the sample code: import snowflake.connector import…
SunilS
  • 2,030
  • 5
  • 34
  • 62
1
vote
1 answer

Eager Inner Join in SQLAlchemy

I must be a moron, because I cannot figure out how to ask SQLAlchemy to perform a simple, non-lazy inner join. In other words, return all the results in a single query. The raw SQL query I would like to run is: select city.population, …
ExactaBox
  • 3,235
  • 16
  • 27
1
vote
1 answer

Python Psycopg executescript method

the Python db-api implementation for sqlite has a convinient method executescript() to execute multi-statement SQL scripts. It is very useful for instance for db creation. See sqlite driver documentation. I can't find a similar one for Psycopg…
Charlie
  • 1,750
  • 15
  • 20
1
vote
3 answers

Python pysqlite not accepting my qmark parameterization

I think I am being a bonehead, maybe not importing the right package, but when I do... from pysqlite2 import dbapi2 as sqlite import types import re import sys ... def create_asgn(self): stmt = "CREATE TABLE ? (login CHAR(8) PRIMARY KEY…
Overflown
  • 1,830
  • 2
  • 19
  • 25
1
vote
0 answers

How to use the IN operator in sqlite3 with parameters?

Python 3.5.2, stdlib sqlite3. I'm trying to issue a SQL query with a dynamic criterion in an IN operator in the WHERE clause: bad code (doesn't work) def top_item_counts_in_installations(cursor, installation_names): return cursor.execute( …
tzot
  • 92,761
  • 29
  • 141
  • 204
1
vote
2 answers

how to update multiple rows in ms access from pandas dataframe

I'm trying to execute this update query from columns in a pandas dataframe: sql = "UPDATE tblhis_ventas SET portabilidad = '%s' WHERE (contrato = '%s' and estado = '%s') " % ( df['portabilidad'], df['contrato'],…
calobeto
  • 13
  • 7
1
vote
1 answer

Create Sqlite database patches while updating

Context: A python 3.6 script is updating a Sqlite database several times a day using sqlite3 module. The database is ~500Mo, each update adds up ~250Ko. Issue: I deliver every updated versions of the database and would like to reduce the size of the…
gleeen.gould
  • 599
  • 1
  • 5
  • 22
1
vote
1 answer

New project Python 3x PostgreSQL 9x and pg8000 1x DBAPI?

I'm starting some new projects and want to know if pg8000 is considered a good choice for a production project? Obviously Python and PostgreSQL are mature products, but I'm concerned about pg8000 both when it comes to maturity and performance. Will…
a2j
  • 453
  • 1
  • 4
  • 11
1 2 3
8 9