Coder Social home page Coder Social logo

python-ibmdb's Introduction

Python support for IBM Db2 for LUW and IBM Db2 for z/OS

Python, DB-API components for IBM Db2 for LUW and IBM Db2 for z/OS

Provides Python interface for connecting to IBM Db2 for LUW and IBM Db2 for z/OS

Components

  1. The ibm_db contains:
    • ibm_db driver: Python driver for IBM Db2 for LUW and IBM Db2 for z/OS databases. Uses the IBM Data Server Driver for ODBC and CLI APIs to connect to IBM Db2 for LUW.
    • ibm_db_dbi: Python driver for IBM Db2 for LUW that complies to the DB-API 2.0 specification.

API Documentation

For more information on the APIs supported by ibm_db, please refer to below link:

https://github.com/ibmdb/python-ibmdb/wiki/APIs

Pre-requisites

Install Python 3.7 <= 3.12. The minimum python version supported by driver is python 3.7 and the latest version supported is python 3.12.

To install ibm_db on z/OS system

Please follow detailed installation instructions as documented here: ibm_db Installation on z/OS

  • SQL1598N Error - It is expected in absence of valid db2connect license. Please click here and read instructions.

For MacOS M1/M2/ Apple Silicon chip system

Important: The driver for IBM DB2 is not compatible with Apple Silicon and will have to run in emulated mode. Please support this request for an Apple Silicon version of the driver to show IBM that you are interested in a native solution.

Several things might be necessary to get ibm_db working on the Apple Silicon architecture:

  • Open new terminal and run command arch -x86_64 /bin/bash or arch -x86_64 /bin/zsh.
  • Verify the output of gcc -v command. It should show Target: x86_64-apple-darwin21 in output.
  • Install Intel Version of Python like: https://www.python.org/ftp/python/3.9.11/python-3.9.11-macosx10.9.pkg
  • Check output of commands python --version , which python and file /usr/local/bin/python commands. It should show /usr/local/bin/python: Mach-O 64-bit executable x86_64
  • Check this link for detailed instructions about installation of ibm_db on MacOS M1/M2 Chip system.

Linux/Unix:

If you face problems due to missing python header files while installing the driver, you would need to install python developer package and retry install. e.g:

    zypper install python-devel
     or
    yum install python-devel

Windows:

  • If a db2 client or server or dsdriver or clidriver is already installed in the system and user has already set installed path to PATH environment variable, then user need to set environment variable IBM_DB_HOME manaully to the installed path before installing ibm_db.

  • To verify it, just execute db2level command before installation of ibm_db. If it works, note down the install directory path and set system level environment variable IBM_DB_HOME as install path shown in output of db2level command.

  • If user has installed clidriver in F:\DSDRIVER and if the "PATH" environment variable has F:\DSDRIVER\bin, then user should also set IBM_DB_HOME to F:\DSDRIVER.

MAC OS:

Db2 V11.5.4 clidriver is built with GCC version 8.4.0 and hence you may need to upgrade to this version if you face problems due to old version of the GCC compiler in your environment while loading the ibm_db library.

Docker Linux containers:

  • You may need to install gcc, python, pip, python-devel, libxml2 and pam if not already installed. Refer to Installation for more details.

Manual Installation

To install ibm_db from source code after clone from git, or to know the detialed installation steps for various platforms, please check INSTALL document.

Installation

  • Python Wheels are built for Linux, MacOS and Windows operating systems for multiple python versions (from python version 3.7 to 3.11). For other platforms, package gets installed from source distribution.

You can install the driver using pip as:

pip install ibm_db

This will install ibm_db and ibm_db_dbi module.

Note: When we install ibm_db package on Linux, MacOS and Windows, pip install ibm_db command install prebuilt Wheel package that includes clidriver too and ignores IBM_DB_HOME or IBM_DB_INSTALLER_URL environment variables if set. Also, auto downloading of clidriver does not happen as clidriver is already present inside wheel package.

To inforce auto downloading of clidriver or to make setting of environment variable IBM_DB_HOME effective, install ibm_db from source distribution using below command:

pip install ibm_db --no-binary :all: --no-cache-dir

If you have to use your own URL for clidriver.tar.gz/.zip please set environment variable

IBM_DB_INSTALLER_URL=full_path_of_clidriver.tar.gz/.zip

When ibm_db get installed from wheel package, you can find clidriver under site_packages directory of Python. You need to copy license file under site_packages/clidriver/license to be effective, if any.

Note: For windows after installing ibm_db, recieves the below error when we try to import ibm_db :

Python 3.11.4 (tags/v3.11.4:d2340ef, Jun  7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ibm_db
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing ibm_db: The specified module could not be found.
>>>

We need to make sure to set dll path of dependent library of clidriver before importing the module as:

import os
os.add_dll_directory('path to clidriver installation until bin')
import ibm_db

e.g:
os.add_dll_directory('C:\\Program Files\\IBM\\CLIDRIVER\\bin')
import ibm_db

Refer https://bugs.python.org/issue36085 for more details.

  • For installing ibm_db on docker Linux container, you can refer as below:
yum install python gcc pam wget python-devel.x86_64 libxml2
use, `yum install python3` to install python 3.x

if pip or pip3 does not exist, install it as:
wget https://bootstrap.pypa.io/get-pip.py
docker cp get-pip.py /root:<containerid>
cd root
python2 get-pip.py or python3 get-pip.py

Install python ibm_db as:
pip install ibm_db
or
pip3 install ibm_db

  • Uninstalling the ibm_db driver :
pip uninstall ibm_db

The ODBC and CLI Driver(clidriver) is automatically downloaded at the time of installation and it is recommended to use this driver. However, if you wish to use an existing installation of clidriver or install the clidriver manually and use it, you can set IBM_DB_HOME environment variable as documented below:

  • Environment Variables: IBM_DB_HOME :

    Set this environment variable to avoid automatic downloading of the clidriver during installation. You could set this to the installation path of ODBC and CLI driver in your environment.
    e.g:

    Windows :
    set IBM_DB_HOME=C:/Users/userid/clidriver
    
    Other platforms:
    export IBM_DB_HOME=/home/userid/clidriver
    

Note: You must need to install ibm_db using command pip install ibm_db --no-binary :all: --no-cache-dir on Linux, Windows and MacOS to make setting of IBM_DB_HOME effective.

You are required to set the library path to the clidriver under IBM_DB_HOME to pick this version of the ODBC and CLI Driver.
e.g:

Windows:
set LIB=%IBM_DB_HOME%/lib;%LIB%

AIX:
export LIBPATH=$IBM_DB_HOME/lib:$LIBPATH

MAC:
export DYLD_LIBRARY_PATH=$IBM_DB_HOME/lib:$DYLD_LIBRARY_PATH

Other platforms:
export LD_LIBRARY_PATH=$IBM_DB_HOME/lib:$LD_LIBRARY_PATH

The ODBC and CLI driver is available for download at Db2 LUW ODBC and CLI Driver. Refer to (License requirements) for more details on the CLI driver for manual download and installation.

  • Installing using Anaconda distribution of python
conda install -c conda-forge ibm_db
  • Supported Platform for Anaconda Installation
Platform Architecture Supported Version
Linux amd64 (x86_64) Yes Latest
Linux ppc64le Yes Latest
Darwin Mac OS x64 Yes Latest
Windows x64 Yes Latest
Windows x32 Yes Latest

Install Intel/x64 version of python on M1 Chip system. Check this link for detailed instructions.

Quick Example

$ python
Python 3.6.5 (default, May 10 2018, 00:54:55)
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ibm_db
>>> #For connecting to local database named pydev for user db2inst1 and password secret, use below example
>>> #ibm_db_conn = ibm_db.connect('pydev', 'db2inst1', 'secret')
>>> #For connecting to remote database named pydev for uid db2inst and pwd secret on host host.test.com, use below example
>>> # Connect using ibm_db
>>> conn_str='database=pydev;hostname=host.test.com;port=portno;protocol=tcpip;uid=db2inst1;pwd=secret'
>>> ibm_db_conn = ibm_db.connect(conn_str,'','')
>>>
>>> # Connect using ibm_db_dbi
>>> import ibm_db_dbi
>>> conn = ibm_db_dbi.Connection(ibm_db_conn)
>>> # create table using ibm_db
>>> create="create table mytable(id int, name varchar(50))"
>>> ibm_db.exec_immediate(ibm_db_conn, create)
<ibm_db.IBM_DBStatement object at 0x7fcc5f44f650>
>>>
>>> # Execute tables API
>>> conn.tables('DB2INST1', '%')
[{'TABLE_CAT': None, 'TABLE_SCHEM': 'DB2INST1', 'TABLE_NAME': 'MYTABLE', 'TABLE_TYPE': 'TABLE', 'REMARKS': None}]
>>>
>>> # Insert 3 rows into the table
>>> insert = "insert into mytable values(?,?)"
>>> params=((1,'Sanders'),(2,'Pernal'),(3,'OBrien'))
>>> stmt_insert = ibm_db.prepare(ibm_db_conn, insert)
>>> ibm_db.execute_many(stmt_insert,params)
3
>>> # Fetch data using ibm_db_dbi
>>> select="select id, name from mytable"
>>> cur = conn.cursor()
>>> cur.execute(select)
True
>>> row=cur.fetchall()
>>> print("{} \t {} \t {}".format(row[0],row[1],row[2]),end="\n")
(1, 'Sanders')   (2, 'Pernal')   (3, 'OBrien')
>>> row=cur.fetchall()
>>> print(row)
[]
>>>
>>> # Fetch data using ibm_db
>>> stmt_select = ibm_db.exec_immediate(ibm_db_conn, select)
>>> cols = ibm_db.fetch_tuple( stmt_select )
>>> print("%s, %s" % (cols[0], cols[1]))
1, Sanders
>>> cols = ibm_db.fetch_tuple( stmt_select )
>>> print("%s, %s" % (cols[0], cols[1]))
2, Pernal
>>> cols = ibm_db.fetch_tuple( stmt_select )
>>> print("%s, %s" % (cols[0], cols[1]))
3, OBrien
>>> cols = ibm_db.fetch_tuple( stmt_select )
>>> print(cols)
False
>>>
>>> # Close connections
>>> cur.close()
True
>>> # Dropping the table created
>>> drop = "drop table mytable"
>>> stmt_delete = ibm_db.exec_immediate(ibm_db_conn,drop)
>>> conn1.tables('DB2INST1','MY%')
[]
>>>
>>> ibm_db.close(ibm_db_conn)
True

Example of SSL Connection String

  • Secure Database Connection using SSL/TSL - ibm_db supports secure connection to Database Server over SSL same as ODBC/CLI driver. If you have SSL Certificate from server or an CA signed certificate, just use it in connection string as below:
Using SSLServerCertificate keyword
 
connStr = "DATABASE=<DATABASE_NAME>;HOSTNAME=<HOSTNAME>;PORT=<SSL_PORT>;UID=<USER_ID>;PWD=<PASSWORD>;" +
          "SECURITY=SSL;SSLServerCertificate=<FULL_PATH_TO_SERVER_CERTIFICATE>;"
conn = ibm_db.connect(connStr,'','')

Note the two extra keywords Security and SSLServerCertificate used in connection string. SSLServerCertificate should point to the SSL Certificate from server or an CA signed certificate. Also, PORT must be SSL port and not the TCPI/IP port. Make sure Db2 server is configured to accept connection on SSL port else ibm_db will throw SQL30081N error.

Value of SSLServerCertificate keyword must be full path of a certificate file generated for client authentication. It normally has *.arm or *.cert or *.pem extension. ibm_db do not support *.jks format file as it is not a certificate file but a Java KeyStore file, extract certificate from it using keytool and then use the *.cert file.

ibm_db uses IBM ODBC/CLI Driver for connectivity and it do not support a *.jks file as keystoredb as keystore.jks is meant for Java applications. Note that *.jks file is a Java Key Store file and it is not an SSL Certificate file. You can extract SSL certificate from JKS file using below keytool command:

keytool -exportcert -alias your_certificate_alias -file client_cert.cert -keystore  keystore.jks

Now, you can use the generated client_cert.cert as the value of SSLServerCertificate in connection string.

Do not use keyworkds like sslConnection=true in connection string as it is a JDBC connection keyword and ibm_db ignores it. Corresponding ibm_db connection keyword for sslConnection is Security hence, use Security=SSL; in connection string instead.

ibm_db supports only ODBC/CLI Driver keywords in connection string: https://www.ibm.com/docs/en/db2/11.5?topic=odbc-cliodbc-configuration-keywords

  • To connect to dashDB in IBM Cloud, use below connection string:
connStr = "DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=passwd;Security=SSL";

We just need to add Security=SSL in connection string to have a secure connection against Db2 server in IBM Cloud.

Note: You can also create a KeyStore DB using GSKit command line tool and use it in connection string along with other keywords as documented in DB2 Infocenter.

  • If you have created a KeyStore DB using GSKit using password or you have got *.kdb file with *.sth file:
Using SSLClientKeyStoreDB and SSLClientKeyStoreDBPassword keyword
 
connStr = "DATABASE=<DATABASE_NAME>;HOSTNAME=<HOSTNAME>;PORT=<SSL_PORT>;UID=<USER_ID>;PWD=<PASSWORD>;" +
          "SECURITY=SSL;SSLClientKeyStoreDB=<FULL_PATH_TO_KEY_STORE_DB>;SSLClientKeyStoreDBPassword=<KEYSTORE_PASSWD>;"
conn = ibm_db.connect(connStr,'','')
Using SSLClientKeyStoreDB and SSLClientKeyStash keyword
 
connStr = "DATABASE=<DATABASE_NAME>;HOSTNAME=<HOSTNAME>;PORT=<SSL_PORT>;UID=<USER_ID>;PWD=<PASSWORD>;" +
          "SECURITY=SSL;SSLClientKeyStoreDB=<FULL_PATH_TO_KEY_STORE_DB>;" +
          "SSLClientKeyStash=<FULL_PATH_TO_CLIENT_KEY_STASH>;"
conn = ibm_db.connect(connStr,'','')

If you have downloaded IBMCertTrustStore from IBM site, ibm_db will not work with it; you need to download Secure Connection Certificates.zip file that comes for IBM DB2 Command line tool(CLP). Secure Connection Certificates.zip has *.kdb and *.sth files that should be used as the value of SSLClientKeystoreDB and SSLClientKeystash in connection string.

For z/OS and iSeries Connectivity and SQL1598N error

  • Connection to Db2 for z/OS or Db2 for i(AS400) Server using ibm_db driver from distributed platforms (Linux, Unix, Windows and MacOS) is not free. It requires either client side or server side license.

  • Connection to Db2 for LUW Server using ibm_db driver is free.

  • ibm_db returns SQL1598N error in absence of a valid db2connect license. SQL1598N error is returned by the Db2 Server to client. To suppress this error, Db2 server must be activated with db2connectactivate utility OR a client side db2connect license file must exist.

  • Db2connect license can be applied on database server or client side. A db2connect license of version 11.5 is required for ibm_db.

  • For activating server side license, you can purchase either Db2 Connect Unlimited Edition for System z® or Db2 Connect Unlimited Edition for System i® license from IBM.

  • Ask your DBA to run db2connectactivate utility on Server to activate db2connect license.

  • If database Server is enabled for db2connect, no need to apply client side db2connect license.

  • If Db2 Server is not db2connectactivated to accept unlimited number of client connection, you must need to apply client side db2connect license.

  • db2connectactivate utility and client side db2connect license both comes together from IBM in a single zip file.

  • Client side db2connect license is a db2con*.lic file that must be copied under clidriver\license directory.

  • If you have a db2jcc_license_cisuz.jar file, it will not work for ibm_db. db2jcc_license_cisuz.jar is a db2connect license file for Java Driver. For non-Java Driver, client side db2connect license comes as a file name db2con*.lic.

  • If environment variable IBM_DB_HOME or IBM_DB_INSTALLER_URL is not set, ibm_db automatically downloads open source driver specific clidriver from https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli and save as site_packages\clidriver. Ignores any other installation.

  • If IBM_DB_HOME or IBM_DB_INSTALLER_URL is set, you need to have same version of db2connect license as installed db2 client. Check db2 client version using db2level command to know version of required db2connect license. The license file should get copied under $IBM_DB_HOME\license directory.

  • If you do not have db2connect license, contact IBM Customer Support to buy db2connect license. Find the db2con*.lic file in the db2connect license shared by IBM and copy it under .../site_packages/clidriver/license directory or $IBM_DB_HOME\license directory (if IBM_DB_HOME is set), to be effective.

  • To know more about license and purchasing cost, please contact IBM Customer Support.

  • To know more about server based licensing viz db2connectactivate, follow below links:

Troubleshooting SQL1598N Error:

If you have copied db2con*.lic file under clidriver/license directory, but still getting SQL1598N Error; try below options:

  • cd clidriver/bin directory and run ./db2level command. Make sure you have the db2connect license of same major and minor version as of clidriver.

  • Make sure the user running python program has read permission for license file.

  • Make sure the user running python program has read-write permission for clidriver/license and clidriver/cfgcache directories as license check utility need to create some cache files under cfgcache and license directories.

  • Validate your license file and connectivity using below db2cli command:

  db2cli validate -connstring "connection string as used in python program" -displaylic

  OR

  db2cli validate -database "dbname:hostname:port" -userid dbuser -passwd dbpasswd -connect -displaylic

If you intend to install the clidriver manually, Following are the details of the client driver versions that you can download from CLIDRIVER to be able to connect to databases on non-LUW servers. You would need the client side license file as per Version for corresponding installation.:

CLIDriver and Client license versions for Specific Platform and Architecture

Platform Architecture Cli Driver Supported Version
AIX ppc aix32_odbc_cli.tar.gz Yes V11.5.8
others aix64_odbc_cli.tar.gz Yes V11.5.8
Darwin x64 macos64_odbc_cli.tar.gz Yes V11.5.8
Linux x64 linuxx64_odbc_cli.tar.gz Yes V11.5.8
s390x s390x64_odbc_cli.tar.gz Yes V11.5.8
s390 s390_odbc_cli.tar.gz Yes V11.1
ppc64 (LE) ppc64le_odbc_cli.tar.gz Yes V11.5.8
ppc64 ppc64_odbc_cli.tar.gz Yes V10.5
ppc32 ppc32_odbc_cli.tar.gz Yes V10.5
others linuxia32_odbc_cli.tar.gz Yes V11.5.8
Windows x64 ntx64_odbc_cli.zip Yes V11.5.8
x32 nt32_odbc_cli.zip Yes V11.5.8
Sun i86pc sunamd64_odbc_cli.tar.gz Yes V10.5
sunamd32_odbc_cli.tar.gz Yes V10.5
sparc sun64_odbc_cli.tar.gz Yes V11.1
sparc sun32_odbc_cli.tar.gz Yes V11.1

You can refer to ODBC and CLI Driver installation for details on how to install the driver manually.

Downloads

Use following pypi web location for downloading source code and binaries ibm_db: https://pypi.python.org/pypi/ibm_db . You can also get the source code by cloning the ibm_db github repository as :

git clone [email protected]:ibmdb/python-ibmdb.git

Support & feedback

Your feedback is very much appreciated and expected through project ibm-db:

Contributing to the ibm_db python project

See CONTRIBUTING

The developer sign-off should include the reference to the DCO in remarks(example below):
DCO 1.1 Signed-off-by: Random J Developer <[email protected]>

Some common issues

1. Installation Issues for missing python.h file

Always use the latest pip

python3 -m pip install --upgrade pip

Install the package python3-dev that delivers the python.h header file

For RHEL use
yum install python3-dev
For Ubuntu use
apt-get install python3-dev
  • Once the above steps works fine, try re-installing ibm_db.

2. SQL30081N Error

If connection fails with SQL30081N error - means ibm_db installation is correct and there is some issue with connection string. Please check database connection info and use correct connection string. If you are using SSL connection, port must be SSL port and connection string must have Security=SSL; and SSLServerCertificate=<full path of cert.arm file>;.

3. Issues with MAC OS X

  • If import ibm_db fails with Symbol not found: ___cxa_throw_bad_array_new_length error or malloc error: Please follow instructions as documented here.

  • If you run into errors for libdb2.dylib as below:

>>> import ibm_db
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/lib/python3.5/site-packages/ibm_db.cpython-35m-darwin.so, 2): Library not loaded: libdb2.dylib
  Referenced from: /usr/local/lib/python3.5/site-packages/ibm_db.cpython-35m-darwin.so
  Reason: image not found

You would need to set DYLD_LIBRARY_PATH to point to lib folder as per the installation location of clidriver in your environment. Assuming the driver is installed at /usr/local/lib/python3.5/site-packages/clidriver, you can set the path as:

export DYLD_LIBRARY_PATH=/usr/local/lib/python3.5/site-packages/clidriver/lib:$DYLD_LIBRARY_PATH

If the issue is not resolved even after setting DYLD_LIBRARY_PATH, you could refer: MAC OS Hints and Tips

Resolving SQL1042C error

If you hit following error while attempting to connect to a database:

>>> import ibm_db
>>> ibm_db.connect("my_connection_string", "", "")
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
 Exception: [IBM][CLI Driver] SQL1042C An unexpected system error occurred. SQLSTATE=58004 SQLCODE=-1042

Set DYLD_LIBRARY_PATH to point to icc folder as per the installation location of clidriver in your environment.

export DYLD_LIBRARY_PATH=/usr/local/lib/python3.5/site-packages/clidriver/lib/icc:$DYLD_LIBRARY_PATH

In case of similar issue in windows platform

set PATH=<clidriver_folder_path>\bin\amd64.VC12.CRT;%PATH%

4. ERROR: Failed building wheel for ibm_db

In case of the error seen while building wheel use the following flag along with ibm_db for installation

To install the package ibm_db it is necessary at first to install the build dependency package - wheel:
pip3 install wheel
Install ibm_db with the pip flag --no-build-isolation:
pip3 install ibm_db --no-build-isolation

5. For Issues on IBM iSeries System (AS400)

  • If you have installed ibm_db on IBM i and need help, please open an issue here.

  • If you have installed ibm_db on distributed platform and want to connect to AS400 server, you must have to use db2connect license. ibm_db do not work with IBM i Access driver.

Testing

Tests displaying Python ibm_db driver code examples are located in the ibm_db_tests directory. A valid config.py will need to be created to configure your Db2 settings. A config.py.sample exists that can be copied and modified for your environment.

  • Set Environment Variables DB2_USER, DB2_PASSWD accordingly.
For example, by sourcing the following ENV variables:
For Linux
export DB2_USER=<Username>
export DB2_PASSWD=<Password>

For windows
set DB2_USER=<Username>
set DB2_PASSWD=<Password>

  • OR
If not using environment variables, update user and password information in
config.json file.

The config.py should look like this:

test_dir =      'ibm_db_tests'         # Location of testsuite file (relative to current directory)
file_path = 'config.json'

with open(file_path, 'r') as file:
    data = json.load(file)

database = data['database']               # Database to connect to
hostname = data['hostname']               # Hostname
port = data['port']                       # Port Number

env_not_set = False
if 'DB2_USER' in os.environ:
     user = os.getenv('DB2_USER')         # User ID to connect with
else:
    user = data['user']
    env_not_set = True
if 'DB2_PASSWD' in os.environ:
    password = os.getenv('DB2_PASSWD')    # Password for given User ID
else:
    password = data['password']
    env_not_set = True

if env_not_set == True:
    warnings.warn("Warning: Environment variable DB2_USER or DB2_PASSWD is not set.")
    print("Please set it before running test file and avoid")
    print("hardcoded password in config.json file." )

Point the database to mydatabase as created by the following command.

The tests that ibm_db driver uses depends on a UTF-8 database. This can be created by running:

  CREATE DATABASE mydatabase USING CODESET UTF-8 TERRITORY US

Some of the tests utilize XML functionality only available in version 9 or later of Db2. While Db2 v8.x is fully supported, two of the tests (test_195.py and test_52949.py) utilize XML functionality. These tests will fail on version 8.x of Db2.

Running the driver testsuite on Linux

In order to run the entire python driver testsuite on Linux, run this command at the command prompt:

  python ibmdb_tests.py

To run a single test, set the environment variable, SINGLE_PYTHON_TEST, to the test filename you would like to run, followed by the previous command.

Running the driver testsuite on Windows

In order to run the entire python driver testsuite on Windows, run this command at the command prompt:

  python ibmdb_tests.py

To run a single test, set the environment variable, SINGLE_PYTHON_TEST, to the test filename you would like to run, followed by the previous command.

Known Limitations for the Python driver

If trusted context is not set up, there will be two failures related to trusted context. When thick client has been used then additional three failures related to create, recreate DB.

ibm_db do not work with arm64 version of python, use x64 version.

Known Limitations for the Python wrapper

  1. The rowcount for select statements can not be generated.
  2. Some warnings from the drivers are not caught by the wrapper. As such these might go unnoticed.

M1 MAC Steps to Install IBM DB and Support Docker RUN

Installation Steps:

Install Podman / Docker:

  • Podman: Follow the instructions provided on the official Podman website to install Podman on your M1 Mac.
  • Docker: Alternatively, you can install Docker using the native Apple Silicon version or the Rosetta-translated Intel version. Choose the method that best fits your requirements.

Install Intel Version of Python:

  1. Download and install the Intel version of Python 3.8 from the official Python website.
  2. After installation, ensure that you set the interpreter to Python 3.8 in your development environment.

Configuration Steps:

Configure Docker for M1:

  • For M1 Macs, ensure compatibility by specifying the platform architecture during Docker build commands: docker build -t <image_name> . --platform=linux/amd64 Alternatively, if you're using Podman: podman build -t <image_name> . --platform=linux/amd64

Build Docker Image (Intel):

  • If you're using an Intel Mac or running Docker with Rosetta translation, use the following command to build your Docker image: docker build -t <image_name> .

Additional Notes:

  • These steps are tailored for M1 Macs to ensure seamless installation and configuration of IBM DB and Docker support.
  • Verify that your Dockerfile and any dependencies are compatible with the specified platform architecture. Follow these steps carefully to set up IBM DB and Docker support on your M1 Mac environment. If you encounter any issues or have further questions, feel free to seek assistance from the community or relevant support channels. Happy coding!

python-ibmdb's People

Contributors

abhi7436 avatar aksanand avatar amukherjee28 avatar anandakshay44 avatar awadhambika avatar bchoudhary6415 avatar bimalkjha avatar cclauss avatar davidmmooney avatar earammak avatar hemlatabhatt avatar hogglo avatar ibmamar avatar jaraco avatar jospaul1 avatar kadler avatar killuazhu avatar kotofos avatar kparihar07 avatar mariobriggs avatar mizi avatar praveen-db2 avatar pschoen-itsc avatar rpriyadh avatar rredburn avatar sabakauser avatar shenanigansd avatar sobolevn avatar tam-lin avatar theophilechevalier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-ibmdb's Issues

Reference counting errors

Numerous reference counting errors in the _python_ibm_db_bind_fetch_helper 
in ibm_db.c can result in the interpreter crashing when the reference 
count on None drops to zero, and cause all values retrieved to be leaked 
(because their reference counts will never reach zero). Problem is present 
in 0.3.0 and 0.2.9 (and presumably earlier versions).

The attached patch against SVN trunk should fix the reference counts in 
that function (there may be other reference counting errors, but I haven't 
checked extensively yet). The patch also cleans up the function by 
consolidating all the op parameter checks (FETCH_ASSOC / INDEX / BOTH) at 
the end of the loop, and fixes a potential SIGSEGV bug (memset was called 
immediately after a malloc before checking the malloc result - the memset 
was redundant anyway, as the buffer is automatically NULL-terminated by 
the SQLGetData function called later).

Original issue reported on code.google.com by [email protected] on 27 Sep 2008 at 2:04

Attachments:

Real datatype is returning wrong values while using ibm_db or ibm_db_dbi

What steps will reproduce the problem?
1. import ibm_db
ibm_db_conn = ibm_db.connect('test', 'db2inst1', 'secret')
import ibm_db_dbi
conn = ibm_db_dbi.Connection(ibm_db_conn)
cur = conn.cursor()
cur.execute("select distinct * from geography where ID = '1'")
cur.rowcount
print cur.fetchone()

stmt = ibm_db.exec_immediate(ibm_db_conn, "select distinct * from 
geography where ID = '1'")
a = ibm_db.fetch_tuple(stmt) 
print a


What is the expected output? What do you see instead?
Expected output is the value in table, instead we see some garbage values.

Please use labels and text to provide additional information.


Original issue reported on code.google.com by [email protected] on 11 Nov 2008 at 9:51

ibm_db.execute raises an exception if I try to debug with pdb after using bind_param with date

What steps will reproduce the problem?
1. I used the following code:
--- CODE BEGIN ---
import os
import ibm_db
import datetime

query = """
SELECT
    CAL_DATE,
    CAL_YEAR
FROM
    DAR.TD_CALENDAR
WHERE
    CAL_DATE > ?
FETCH FIRST 5 ROWS ONLY;
"""

creds_file = os.path.join(os.getenv("HOME"), '.db2w.credentials')
user, passwd = open(creds_file).read().splitlines()[:2]
conn = ibm_db.connect('db2w', user, passwd)
stmt = ibm_db.prepare(conn, query)
how_far = datetime.datetime.now() - datetime.timedelta(hours=200)
print ibm_db.bind_param(stmt, 1, str(how_far.date()),
ibm_db.SQL_PARAM_INPUT, ibm_db.SQL_TYPE_DATE)
print ibm_db.execute(stmt)
row = ibm_db.fetch_tuple(stmt)
while row:
    print row
    row = ibm_db.fetch_tuple(stmt)
--- CODE END ---

2. If I execute the code normally, everything works:
$ python test_query.py 
True
True
('2008-09-23', 2008)
('2008-09-24', 2008)
('2008-09-25', 2008)
('2008-09-26', 2008)
('2008-09-27', 2008)

3. If I try to debug the code, there is an exception:
Sample IPython debugging session:
In [1]: run -d test_query.py
Breakpoint 1 at /home/user/Work/sample_query/test_query.py:1
NOTE: Enter 'c' at the ipdb>  prompt to start your script.
> <string>(1)<module>()

ipdb> c
> /home/user/Work/sample_query/test_query.py(1)<module>()
1---> 1 import os
      2 import ibm_db
      3 import datetime

ipdb> b 23
Breakpoint 2 at /home/user/Work/sample_query/test_query.py:23
ipdb> c
True
> /home/user/Work/sample_query/test_query.py(23)<module>()
     22 print ibm_db.bind_param(stmt, 1, str(how_far.date()),
ibm_db.SQL_PARAM_INPUT, ibm_db.SQL_TYPE_DATE)
2--> 23 print ibm_db.execute(stmt)
     24 row = ibm_db.fetch_tuple(stmt)

ipdb> n
Exception: 'Statement Execute Failed: [IBM][CLI Driver] CLI0113E  SQLSTATE
22007: An invalid datetime format ...d; that is, an invalid string
representation or value was specified. SQLSTATE=22007 SQLCODE=-99999'
> /home/user/Work/sample_query/test_query.py(23)<module>()
     22 print ibm_db.bind_param(stmt, 1, str(how_far.date()),
ibm_db.SQL_PARAM_INPUT, ibm_db.SQL_TYPE_DATE)
2--> 23 print ibm_db.execute(stmt)
     24 row = ibm_db.fetch_tuple(stmt)

ipdb> 


What is the expected output? What do you see instead?
I expect to be able to debug without having an exception.

What version of the product are you using? On what operating system?
Python 2.5, ibm_db 0.3.0, db2level returns:
DB21085I  Instance "user" uses "32" bits and DB2 code release "SQL08028" 
with level identifier "03090106".
Informational tokens are "DB2 v8.1.2.136", "s070720", "MI00189", and FixPak 
"15".
Product is installed at "/opt/IBM/db2/V8.1".

Please provide any additional information below.
I'm on Ubuntu Hardy Heron 8.04.1. The program also raises an exception if I
use plain old pdb.

Original issue reported on code.google.com by [email protected] on 30 Sep 2008 at 9:06

Attachments:

creation of table via sqlalchemy fails for ibm_db because numeric column is translated to a wrong decimal one.

What steps will reproduce the problem?
1. define a simple table like:
foo = Table('foo', meta,
    Column('somecol', NUMERIC(length=5, precision=2)),
    Column('othercol', NUMERIC(length=8, precision=0)),
)

2. try to foo.create() 

What is the expected output? What do you see instead?
I expect that the table is created.
I see this instead:
    raise exceptions.DBAPIError.instance(statement, parameters, e,
connection_invalidated=is_disconnect)
sqlalchemy.exceptions.ProgrammingError: (ProgrammingError)
ibm_db_dbi::ProgrammingError: Statement Execute Failed: [IBM][CLI
Driver][DB2/LINUX] SQL0604N  The length, precision, or scale attribute for
column, distinct type, structured type, array type, attribute of structured
type, routine, cast target type, type mapping, or global variable
"DECIMAL(2, 5)" is not valid.  SQLSTATE=42611 SQLCODE=-604 '\nCREATE TABLE
foo (\n\tsomecol DECIMAL(2, 5), \n\tothercol DECIMAL(31,0)\n)\n\n' {}


What version of the product are you using? On what operating system?
ibm_db 0.2.6
ibm_db_sa 0.1.1
python 2.5
sqlalchemy 0.4.3

Please provide any additional information below.
Looking at the creation statement I can see it is wrong.
CREATE TABLE foo (
    somecol DECIMAL(2, 5),
    othercol DECIMAL(31,0)
)

It should be
CREATE TABLE foo (
    somecol NUMERIC(5, 2),
    othercol NUMERIC(8,0)
)


Original issue reported on code.google.com by [email protected] on 5 Mar 2008 at 11:05

django adapter: query.DB2QueryClass.as_sql to use 'fetch first' when has high_mark (limit) and no low_mark (offset)

While db2 doesn't support 'offset' in sql, and django orm needs this,
currently this is implemented with ROW_NUMBER() workaround.  

This is probably the best way to simulate offset, but disadvantage is that
the logic of code is complex, and in my opinion, can become fragile because
of this, e.g. in the case when django side changes. There is also a
question of performance. 

Whatever, to make things less 'fragile', and since db2 supports sql "limit"
part (select ... fetch first), my suggestion is to split the limit/offset
logic to two parts, i.e. to take advantage of db2 "fetch first" sql select
extension.

Idea:
    query.DB2QueryClass.as_sql

    if not (with_limits and (self.high_mark is not None or self.low_mark)):
        return super(DB2QueryClass, self).as_sql(False, with_col_aliases)

    # ----------- NEW_LOGIC: begin -------------

    elif with_limits and self.high_mark is not None and not self.low_mark:
        # only high - limit without offset
        assert self.high_mark > 0
        sql, params = super(Db2Query, self).as_sql(with_limits=False,
                                                   with_col_aliases=True)
        sql = "%s FETCH FIRST %d ROWS ONLY" % (sql, self.high_mark)

    # ----------- NEW_LOGIC: end -------------

    else:                
        self.pre_sql_setup()
        ...

Since I had similar problem when implementing db2 sqlalchemy adapter, I
have implemented only 'fetch first' part. But during the testing new
problem occured which is illustrated by the following example:

    select ...  from (select ... from ... fetch first) ...  

This example fails since 'fetch first' in subselect is not supported by
db2. I don't know if such sql construction is possible by the django
ORM (subselects with limits), but if it is and the whole idea is to be
implemented then this case should be considered too. 


Original issue reported on code.google.com by [email protected] on 26 Jun 2009 at 9:23

Add support for 2 phase commit transactions

I would like to have ability to do 2PC commits between two DB2 9LUW using
DB2 as transaction manager.

Original issue reported on code.google.com by kolar.radim on 25 Jun 2009 at 4:30

BIGINT column returned as str type

What steps will reproduce the problem?
1. selecting a bigint column from a table

What is the expected output? What do you see instead?
I expect python int/long type but i get str instead

What version of the product are you using? On what operating system?
ibm_db 0.2.5 - Suse Linux 9.3

Please provide any additional information below.
I fix it by adding in _fix_return_data_type (ibm_db_dbi.py) the code below
if type == 'INT':
    row[index] = int(row[index])

but in this way i will also convert INT and SMALLINT that don't need conversion

Original issue reported on code.google.com by [email protected] on 13 Mar 2008 at 2:17

Every single SQL query does an extra count() query

There is no requirement to return the rowcount from the execute() method
and the extra count() query that is executed every time could well be
costly. If the database server cannot return the number of affected rows
easily, I would recommend this be omitted from the return value of execute().

The "rowcount" attribute can retrieve the information lazily, if that's
desired, but we shouldn't have to pay this penalty for every single query.

Original issue reported on code.google.com by [email protected] on 21 Mar 2008 at 7:56

Assuming column name is ID

What steps will reproduce the problem?
1. Trying to load data into a table using manage.py loaddata in django


What version of the product are you using? On what operating system?
1.0

Please provide any additional information below.
The error 
: ibm_db_dbi::ProgrammingError: [IBM][CLI Driver][DB2/DARWIN] SQL0206N 
"ID" is not valid in the context where it is used.  SQLSTATE=42703 
SQLCODE=-206

In:
operations.py 
sequence_reset_sql (Line 171)


Original issue reported on code.google.com by [email protected] on 7 Dec 2009 at 8:58

django adapter: To simplify implementation of creation.sql_create_model

creation.sql_create_model implementation looks very complex. Declaration:

    # As DB2 does not allow to insert NULL value in UNIQUE col, hence
modifing model.
    def sql_create_model(self, model, style, known_models=set()):

Didn't investigated too much, but it sounds to me that much smaller
adaptation on the django side of creation.sql_create could solve this much
simplier. If this is the case, then probably
django.db.backends.DatabaseFeatures needs new boolean setting for
activating this.

Original issue reported on code.google.com by [email protected] on 26 Jun 2009 at 9:15

FUTURE: ibm_db.pyd - cpython implementation replace with pure python+ctypes implementation

ctypes (http://docs.python.org/library/ctypes.html) is integral part of
python since 2.5 (for python 2.3 and 2.4 download can be found in original
project page http://sourceforge.net/projects/ctypes/files/). 

recently we did some python wrapping of some native libraries (originally
developed in C/, compiled on win32 - results are in dll-s). We did it with
python.ctypes and not with cpython/swig/boost or ... Our experience is
excellent, this approach is for reccomendation: 
 - it can be easily adapted to be platform independent - ctypes works
everywhere
 - everything we wanted to get from dll - with ctypes we could get it
(functions, params, structs, byref, addresses ...)
 - the best thing is - we don't need to recompile anything in the case of
change of wrapper source code and/or for different platform (python 2.*,
different OS-es etc.)
 - it is fast - critical parts are in C native libraries, wrapper doesn't
have and time-critical parts

Based on this experience, my reccommendation is that every new and if
possible for existing should be developed in pure python using ctypes when
needed to access some native functions.

So my suggestion is, at least, to take this in consideration when thinking
about next features of ibm_db project: 
 - to replace ibm_db.pyd with pure python+ctypes.

I have looked source of ibm_db.c and the task of converting this to ctypes
won't be easy and fast. On other hand this conversion could get many
benefits: no issues with diff. python versions, no issues with different
operation systems, easy adaptation for different db2 client versions, solve
issue of new python 3.* cpython api backward incompatible changes, easier
and faster maintainance, development and deployment ...

Original issue reported on code.google.com by [email protected] on 9 Jan 2010 at 5:29

Exception when use `fetch first N rows only optimize for N rows`

What steps will reproduce the problem?



In [12]: import ibm_db_dbi as db
In [13]: con = db.connect('DSN=nsi23')
In [14]: cur = con.cursor()
In [15]: cur.execute('select * from sysibm.sysdummy1  fetch first 12 rows
only optimize for 12 rows')
---------------------------------------------------------------------------
ProgrammingError                          Traceback (most recent call last)

c:\python25\lib\site-packages\ibm_db-0.2.5-py2.5-win32.egg\ibm_db_dbi.py in
execute(self, operation, parameters)
   1008         self._prepare_helper(operation)
   1009         self._execute_helper(None, parameters)
-> 1010         return self._set_rowcount(operation, parameters)
   1011
   1012

c:\python25\lib\site-packages\ibm_db-0.2.5-py2.5-win32.egg\ibm_db_dbi.py in
_set_rowcount(self, operation, parameters)
    947                 count_row_tuple = ibm_db.fetch_tuple(stmt_handler)
    948             except Exception, inst:
--> 949                 raise _get_exception(inst)
    950
    951             self.__rowcount = count_row_tuple[0]

ProgrammingError: ibm_db_dbi::ProgrammingError: [IBM][CLI Driver][DB2/NT]
SQL0104N  An unexpected token "optimize" was found following "h first 12
rows only".  Expected tokens may include:  ")".  SQLSTATE=42601\r SQLCODE=-104




What is the expected output? What do you see instead?
pyodbc, ceodbc, mxodbc works fine with this statement


What version of the product are you using? On what operating system?
* ibm_db-0.2.5-py2.5-win32.egg
* Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32 (WinXPsp2)



Original issue reported on code.google.com by [email protected] on 15 Feb 2008 at 10:32

Django adapter (alpha) based on PyDB2 - contribution

Hi, 
I was inspired by this thread:
http://groups.google.com/group/ibm_db/browse_thread/thread/18d3eec89eca7e7b
so I send you Django adapter (alpha) based on PyDB2. 

This is based on Django 0.96 release. I needed django working on db2 and
did adapter by looking at code of other adapters. Module is functional in
my environment, but ... Didn't runned django tests against db2 module, so
probably lot of problems still exist.

In attachment you'll find:
 - db2 folder from django.db.backends folder
 - django_db2_adapter_0.96.diff - diff agains slightly modified django 0.96
release

I'm very glad that this project exists, finally python/sqlalchemy have
proper db2 driver. I'm hoping that you'll use this work (or not ;) ), and 
fill the gap for db2-pythonists - django-db2 adapter. Continue with the
good work. 

Regards, 
Robert

Original issue reported on code.google.com by [email protected] on 9 Apr 2008 at 1:30

Attachments:

tests fail in linux-ppc64 (IBM pSeries + xlc)

Installing on linux-ppc64, building gives 3 Warnings + 1 Error when
compiling, and supplied tests gives:

Ran 141 tests in 8.991s

FAILED (failures=32, errors=56)

Attached file is the output from doing
$>python tests.py 2>error.log

Errors should not be due to incorrect locales as LANG=en_US.UTF-8


What version of the product are you using? On what operating system?

SUSE LINUX Enterprise Server 9 (ppc)
DB2 SDK 8.2.9
Python 2.5
IBM XL C/C++ Advanced Edition V8.0 for Linux



Please provide any additional information below.

In ibm_db.c you get 3 warnings (lines 1013, 3632 and 3723) due to function
arguments of wrong type, these can be avoided by explicit casting to the
expected types - this is not critical, but I prefer that distributed code
should be free of such "trivial" things.

You also get a compile error because "SQL_DECFLOAT" is not known - it
appears TWICE??? in lines 7289 and 7290. My not-so-pretty fix is to comment
out both lines as chances are that we will never use this type.

Hopefully someone can help us out, we would VERY much like to switch to
ibm_db because the Python to DB2 interface we use today is unstable.



Original issue reported on code.google.com by [email protected] on 19 Jun 2008 at 12:25

Attachments:

Test DB creation in Django backend should respect verbosity

The methods create_test_db and destroy_test_db of DatabaseCreation in 
ibm_db_django/django/db/backends/db2/creation.py always print messages to 
stdout, which can 
cause problems in applications which perform scripted calls to management 
commands in 
environments where doing so is either undesired or forbidden (e.g., WSGI 
restricts access to 
stdout).

To resolve this, these methods should only print messages when the "verbosity" 
argument is 1 or 
greater, per Django's documentation:

http://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-verbosity

Original issue reported on code.google.com by [email protected] on 20 Jun 2009 at 7:31

setup issue: quit() vs sys.exit()


If the IBM_DB_DIR and IBM_DB_LIB environment variables aren't set up,
setup.py tries to exit with quit().  quit is a built-in string, not a
function, so setup exits with an unintended error.   To resolve this issue,
use sys.exit() instead.

example:

$ python setup.py develop
IBM DataServer environment not set. Please refer to the README for more
information on building the driver
Traceback (most recent call last):
  File "setup.py", line 16, in <module>
    quit()
TypeError: 'str' object is not callable

Original issue reported on code.google.com by [email protected] on 3 Apr 2008 at 7:43

django_adapter: host/port connection options are obligatory

by default most of django database attributes have default values "" (see
django.conf.global_settings). 
Logic done in ibm_db_django.base is like this: 

             if (isinstance(database_user, types.StringType) or 
               isinstance(database_user, types.UnicodeType)):
                kwargs['user'] = database_user

this mean that if you don't specify in your settings user at all kwargs[]
will hold "user" with "" value.

This is especially odd for host and port options, since this term: 

if ((isinstance(database_port, types.StringType) or
                isinstance(database_port, types.UnicodeType)) and 
                (isinstance(database_host, types.StringType) or
                isinstance(database_host, types.UnicodeType))): 

will allways be executed - what makes these two params required. 

Workaround - one can define HOST/PORT vars = None.

Proposed solution: 
            if (isinstance(database_pass, types.StringType) or
               isinstance(database_pass, types.UnicodeType)):
-> 
            if database_pass:

for port/host:

            if ((isinstance(database_port, types.StringType) or
                isinstance(database_port, types.UnicodeType)) and 
                (isinstance(database_host, types.StringType) or
                isinstance(database_host, types.UnicodeType))):

->
            if database_port and host:

----------------

btw. simplified version of isinstance:
            if (isinstance(database_host, types.StringType) or
               isinstance(database_host, types.UnicodeType)):
->
            if isinstance(database_host, basestring):

no need for "import types".


Original issue reported on code.google.com by [email protected] on 29 Mar 2010 at 11:41

Major latency issues with remote fetches

What steps will reproduce the problem?
1. Use PyDB2 to execute a query against a (fairly distant) remote database
2. Use ibm_db to execute the same query against the same remote database
3. Compare the times

What is the expected output? What do you see instead?

I've been testing my application (which can use pyodbc, PyDB2, or ibm_db 
to connect to DB2). The 0.4.0 release of the ibm_db driver seems to have 
fixed the crashing issues I was experienced with the driver previously, 
and when used against a local database the driver performs tolerably well 
(a couple of seconds slower than PyDB2, but no big deal).

However, when used against a remote database the difference is /vast/. 
Specifically, when querying a database with a ping time of 140ms, ibm_db 
is 4 orders of magnitude slower than PyDB2; so slow, it's effectively 
unusable. Here's the result of a quick test script I bashed together to 
compare the two drivers (I've attached the script):

Testing PyDB2
Executed query in 0:00:00.151270
Fetched 138 rows in 0:00:00.001147
Mean row fetch time: 0:00:00.000010
Median row fetch time: 0:00:00.000010

Testing ibm_db_dbi
Executed query in 0:00:00.577083
Fetched 138 rows in 0:00:19.619216
Mean row fetch time: 0:00:00.142121
Median row fetch time: 0:00:00.141764

What version of the product are you using? On what operating system?

The above results were from comparing ibm_db 0.4.0 to PyDB2 1.1.1 on 
Ubuntu Linux Server 7.10 for AMD64 with DB2 9.5 Enterprise Server Edition. 
The target database for the results above was a DB2 8 for z/OS instance. 
I've also tested the script against DB2 8 on AIX 64-bit, DB2 9.5 on Linux 
64-bit, and DB2 8 on Windows 32-bit. All showed performance degradation, 
with the amount being primarily dictated by the roundtrip time to the 
server.

Please provide any additional information below.

I haven't dug into this side of the fetching code yet, but I'll try and 
have a look this week. Either way, there's definitely something seriously 
wrong in there that'll need fixing before the driver'll be practical for 
any kind of heavy remote work. For example: I currently find myself in the 
amusing situation that my application will take 8 minutes to fetch a 
pretty large dataset from the remote z/OS instance with PyDB2 ... and 
approximately 3 months with ibm_db!! (assuming I've done my math right :-)

Original issue reported on code.google.com by [email protected] on 15 Oct 2008 at 12:01

Attachments:

Exception when fetching DECIMAL with comma as the decimal point

What steps will reproduce the problem?

1.
 -- My DB2® subsystem is tailored to use a comma as the decimal point.

 CREATE TABLE TMP.DECIMAL_TEST
 (  FLD    DECIMAL(8, 1)  );

 INSERT INTO TMP.DECIMAL_TEST
 VALUES 12.34;

2.
 import ibm_db_dbi as db

 con = db.connect('DSN=nsi23')
 cur = con.cursor()
 cur.execute('select fld from tmp.decimal_test ')
 print cur.fetchall()


What is the expected output? 

[[12.34],]

What do you see instead?

Traceback (most recent call last):
  File "tst.py", line 6, in <module>
    print cur.fetchall()
  File
"c:\python25\lib\site-packages\ibm_db-0.2.9-py2.5-win32.egg\ibm_db_dbi.py",
line 1134, in fetchall
    return self._fetch_helper()
  File
"c:\python25\lib\site-packages\ibm_db-0.2.9-py2.5-win32.egg\ibm_db_dbi.py",
line 1095, in _fetch_helper
    row_list.append(self._fix_return_data_type(row))
  File
"c:\python25\lib\site-packages\ibm_db-0.2.9-py2.5-win32.egg\ibm_db_dbi.py",
line 1205, in _fix_return_data_type
    raise DataError("Data type format error: "+ str(inst))
ibm_db_dbi.DataError: ibm_db_dbi::DataError: Data type format error:
Invalid literal for Decimal: '12,34'


What version of the product are you using? On what operating system?
ibm_db-0.2.9-py2.5-win32.egg
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on win32 Windows XP sp2 v.5.1.2600
DB2 client v9.5.0.808
DB2 server v8.1.16.429 @ Windows 2003


Original issue reported on code.google.com by [email protected] on 8 May 2008 at 3:21

VALUES queries result in SQL1224 error

What steps will reproduce the problem?
1. Attempt to execute a query with the VALUES statement
2. Watch it die!

What is the expected output? What do you see instead?
The expected output is the result of the VALUES statement


What version of the product are you using? On what operating system?
ibm_db version 1.01 under Python 2.6 on 64-bit Linux 2.6.31 with DB2 
Enterprise Edition 9.7 FP1


Please provide any additional information below.
Here's a simple script to reproduce the error:

#!/usr/bin/env python
import ibm_db_dbi
conn = ibm_db_dbi.connect('SAMPLE')
cur = conn.cursor()
cur.execute('VALUES CURRENT DATE')
# ^-- Dies here for me
cur.fetchall()

I've tested a fairly wide variety of queries involving VALUES (including 
wrapped in a SELECT, wrapped in a CTE, joined with other tables, and 
querying SYSIBM.SYSDUMMY1 which is actually a VALUES statement wrapped in a 
view), and they all fail.

Original issue reported on code.google.com by [email protected] on 31 Mar 2010 at 9:26

django adapter: To add to operations.DatabaseOperations method tablespace_sql

operations.DatabaseOperations method tablespace_sql which django uses
is currently supported only by oracle adapter. This method can be easily
implemented for db2 too. 

There are some settings in model which define this property for table
(db_tablespace?). 

Example of implementation:

def tablespace_sql(self, tablespace, inline=False):
    return "IN %s" % self.quote_name(tablespace)


btw. other issue which is related to tablespace is that in oracle adapter
they use temporary tablespace when creating and destroying test database.
Maybe similar thing can be done in db2 (or to use temp tables?)

Original issue reported on code.google.com by [email protected] on 26 Jun 2009 at 9:04

Implement IBM_DB_SA for the current version of SQLAlchemy

What steps will reproduce the problem?
1. Python 2.5.4/Win XP/DB2 v8.1.17.789, SQLAlchemy-0.5.4p2, ibm_db-0.7.2.1-
py2.5-win32, ibm_db_sa-0.1.6-py2.5 installed
2. Trying to run `IBM_DB SA adapter sanity test` from http://
code.google.com/p/ibm-db/wiki/README

What is the expected output? What do you see instead?
    Traceback (most recent call last):
      File "test1.py", line 3, in <module>
        import ibm_db_sa.ibm_db_sa
      File "c:\python25\lib\site-packages\ibm_db_sa-0.1.6-py2.5.egg
\ibm_db_sa\ibm_db_sa.py", line 24, in <module>
        from sqlalchemy import sql, engine, schema, exceptions, logging
    ImportError: cannot import name logging



Original issue reported on code.google.com by [email protected] on 1 Jun 2009 at 3:08

sets module deprecation warning in Python 2.6

What steps will reproduce the problem?
1. import ibm_db_dbi
2. Warning prints:

/usr/local/lib/python2.6/dist-packages/ibm_db-1.0-py2.6-linux-i686.egg/ibm_db_db
i.py:25: 
DeprecationWarning: the sets module is deprecated
  from sets import ImmutableSet

Code in ibm_db_dbi should probably:

try:
    frozenset()
except NameError:
    from sets import ImmutableSet

to maintain forward and backward compat without the warning.

Original issue reported on code.google.com by [email protected] on 2 Oct 2009 at 2:46

How do I use ibm_db_sa?

What steps will reproduce the problem?
1. install sqlalchemy 
2. install ibm_db
3. install ibm_db_sa
4. import sqlalchemy; sqlalchemy.create_engine('ibm_db_sa:///') ->
ImportError: unknown database 'ibm_db_sa' 

Original issue reported on code.google.com by [email protected] on 14 Feb 2008 at 10:39

Do not require installation into django.db for Django backend

django.db is not a setuptools namespace package, so installation of the Django 
backend is likely to 
be problematic. At any rate, Django can use database backends from any location 
on the Python 
path (DATABASE_ENGINE can be either the name of a bundled backend, or a dotted 
Python module 
path to a third-party backend), specifically to enable the use of third-party 
backends.

Original issue reported on code.google.com by [email protected] on 20 Jun 2009 at 7:07

Does not compile for Python 2.4.

Py_ssize_t type isn't defined in Python 2.4 headers and int is used
instead. The following trivial patch helps (although it is not perfect -
PY_MAJOR_VERSION should also be checked).


diff -ruN ibm_db-1.0-old/ibm_db.h ibm_db-1.0-new/ibm_db.h
--- ibm_db-1.0-old/ibm_db.h     2009-05-21 07:59:01.000000000 +0200
+++ ibm_db-1.0-new/ibm_db.h     2010-01-27 13:30:14.000000000 +0100
@@ -16,6 +16,11 @@
 #include <Python.h>
 #include <structmember.h>

+/* Fix for non-existent Py_ssize_t type in Python 2.4 */
+#if PY_MINOR_VERSION == 4
+#define Py_ssize_t int
+#endif
+
 #define NUM2LONG(data) PyInt_AsLong(data)
 #define STR2CSTR(data) PyString_AsString(data)
 #define NIL_P(ptr) (ptr == NULL)

Original issue reported on code.google.com by [email protected] on 28 Jan 2010 at 2:32

django adapter: to implement base.DatabaseWrapper.server_version property

This is minor thing, but probably can be useful in the future. 
mysql adapter defines in DatabaseWrapper class server_version property and
get_server_version method in order to make distinctions in some part of the
code depending of the db server version. I have done similar based on PyDB2
adapter like this:

    server_version_re = re.compile(r"dbmsVersion: (.*)>")

    def get_server_version(self):
        """ <open connection at c91a90, serverName: DB2     , dbmsName:
DB2/NT, dbmsVersion: 07.02.0009> 
        this function will return (7,2,9)
        """
        if not self.server_version:
            if not self._valid_connection():
                self.cursor() # creates connection
            m = server_version_re.search(str(self.connection))
            if not m:
                raise Exception('Unable to determine Db2 version from
version string %r' % str(self.connection))
            self.server_version = tuple([int(x) for x in
m.groups()[0].split(".")])
        return self.server_version

Probably this information can also be useful from end-users' viewpoint
(maybe django.db.BaseDatabaseWrapper should have such property/method also).

Original issue reported on code.google.com by [email protected] on 26 Jun 2009 at 9:13

setup.py relies on non-standard environment variables

What steps will reproduce the problem?

1. Run setup.py


What is the expected output? What do you see instead?

The setup script returns an error unless extra environment variables are 
set. Unfortunately, the error message doesn't explicitly state what 
variables are to be set - it simply refers the user to the README file. In 
the case of an egg installation (which appears to be the recommended 
method), many users won't know how to extract the README from the egg. 
Assuming they do, the README also has a minor issue: "path_to_sqllib" does 
not clearly describe (in the case of Linux/UNIX) whether the path to the 
installation, or the instance is required.

Overall, it would simply be better if the script relied solely on the 
"standard" environment, as set by the db2profile script on Linux/UNIX, or 
the db2cmd process on Windows. 


What version of the product are you using? On what operating system?

0.2.9 and 0.3.0 on Linux


Please provide any additional information below.

The attached patch uses the DB2INSTANCE environment variable (as set by 
db2profile) on Linux/UNIX, and a simple PATH search for the CLP on 
Windows, to set up the build environment. The messages used in the case of 
errors or warnings are concise, but reasonably clear. If a DB2 
installation is located and the build can proceed, the script outputs all 
the paths it will be using (include, library, etc). The script includes a 
well commented, simple means for advanced users to override the paths used 
(set the PATH variables at the top of the script), which could easily be 
extended if an interactive version were required.

Original issue reported on code.google.com by [email protected] on 27 Sep 2008 at 11:41

Attachments:

Cannot use Python variables with ibm_db.bind_param

-What steps will reproduce the problem?
I used the sample code (attached to this issue)

--- BEGIN CODE ---
import os
import ibm_db
import datetime

query = """
SELECT
    CAL_DATE,
    CAL_YEAR
FROM
    DAR.TD_CALENDAR
WHERE
    CAL_DATE > ?
FETCH FIRST 5 ROWS ONLY;
"""

creds_file = os.path.join(os.getenv("HOME"), '.db2w.credentials')
user, passwd = open(creds_file).read().splitlines()[:2]
conn = ibm_db.connect('db2w', user, passwd)
stmt = ibm_db.prepare(conn, query)
how_far = datetime.datetime.now() - datetime.timedelta(hours=200)
# Notice how the parameter is a native Python datetime.date type
print ibm_db.bind_param(stmt, 1, how_far.date(), ibm_db.SQL_PARAM_INPUT,
ibm_db.SQL_TYPE_DATE)
print ibm_db.execute(stmt)
row = ibm_db.fetch_tuple(stmt)
while row:
    print row
    row = ibm_db.fetch_tuple(stmt)
--- END CODE ---

What is the expected output? What do you see instead?
I expect to have a working query instead I get the following exception:
True
Traceback (most recent call last):
  File "test_query.py", line 23, in <module>
    print ibm_db.execute(stmt)
Exception: Binding Error 3:

The API doc says this for ibm_db.bind_param:
----
ibm_db.bind_param

    Py_True/Py_None ibm_db.bind_param resource stmt, int parameter-number,
        string variable [, int parameter-type [, int data-type [, int   
        precision [, int scale [, int size[]]]]]] ) 

variable

    A Python variable to bind to the parameter specified by parameter-number. 
----
So I expect to be able to use a datetime.date to bind to the query. If I
convert to a string, it works (except while debugging, I will open another
issue for this).

What version of the product are you using? On what operating system?
Python 2.5, ibm_db 0.3.0, db2level returns:
DB21085I  Instance "user" uses "32" bits and DB2 code release "SQL08028" 
with level identifier "03090106".
Informational tokens are "DB2 v8.1.2.136", "s070720", "MI00189", and FixPak 
"15".
Product is installed at "/opt/IBM/db2/V8.1".

Original issue reported on code.google.com by [email protected] on 30 Sep 2008 at 8:52

Attachments:

ibm_db_dbi.Connection.tables() returns empty list

-What steps will reproduce the problem?
Sample IPython session:

In [1]: import ibm_db_dbi

In [2]: passwd = __import__('getpass').getpass()
Password: 

In [3]: conn = ibm_db_dbi.connect('db', 'user', passwd)

In [4]: conn.tables()
Out[4]: []

In [5]: import ibm_db

In [6]: conn = ibm_db.connect('db', 'user', passwd)

In [7]: stmt = ibm_db.tables(conn)

In [8]: ibm_db.fetch_tuple(stmt)
Out[8]: (None, 'DSN8810', 'DSN_STATEMENT_CACHE_AUX', 'AUXILIARY TABLE', '')

In [9]: ibm_db.fetch_tuple(stmt)
Out[9]: (None, 'SYSIBM', 'SYSJARCLASS_SOURCE', 'AUXILIARY TABLE', '')

-What is the expected output? What do you see instead?
With conn.tables() I expect to see a list of table metadata, I instead get
an empty list.

-What version of the product are you using? On what operating system?
Python 2.5, ibm_db 0.3.0, db2level returns:
DB21085I  Instance "user" uses "32" bits and DB2 code release "SQL08028" 
with level identifier "03090106".
Informational tokens are "DB2 v8.1.2.136", "s070720", "MI00189", and FixPak 
"15".
Product is installed at "/opt/IBM/db2/V8.1".

Original issue reported on code.google.com by [email protected] on 30 Sep 2008 at 8:11

ibm_db.pyd is not thread-safe (with patch)

ibm_db version 1.0.1 (latest, win32). We running some python code in
parallel - several threads, and each thread does access to DB2 database
using ibm_db adapter. This causes python.exe (win32) to crash - without
much information left behind - traceback is messed-up.

Looking into to C code of ibm_db.c I found no thread-safe blocks
(http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-
lock).
Therefore I patched ibm_db.c with:

   Py_BEGIN_ALLOW_THREADS;
   ...
   Py_END_ALLOW_THREADS;

for following db2 sql api calls:

   SQLConnect
   SQLExecute
   SQLFetchScroll

With this patch ibm_db.pyd doesn't cause any fatal failure problems in
threading scenario. 

In attachment one can find patch of ibm_db.c, and pyd for python 2.5 and 2.6.

Suggestion: if you could include tests for threading scenario in your
unit-test set.

Original issue reported on code.google.com by [email protected] on 1 Apr 2010 at 2:22

Attachments:

Jython support

What steps will reproduce the problem?
1. Run project with jython instead with cpython

Original issue reported on code.google.com by [email protected] on 17 Sep 2009 at 7:57

Syntax errors in _get_exception()

(From the 0.2.7 source)

In the _get_exception() method, both "warning_error_tuple" and
"integrity_error_tuple" are not tuples. They are strings. 

In Python, ("x",) is a one-tuple, ("x") is just a parenthesised string and
is parsed as a string. Since IntegrityError is one of the errors affected
here, this is quite serious, as constraint violations will not be correctly
reported.

Original issue reported on code.google.com by [email protected] on 21 Mar 2008 at 7:57

Prepare doesn't insert correctly int/long python types in a BIGINT column

What steps will reproduce the problem?
1. db2 "create table test(a bigint)"
2. stmt = ibm_db.prepare(db,"insert into test values(?)")
3. ibm_db.execute(stmt,(9999999999999,))

What is the expected output? What do you see instead?
I expect 9999999999999
but i get
1316134911

What version of the product are you using? On what operating system?
0.4.1

Please provide any additional information below.

I write a patch for ibm_db.c
In function _python_ibm_db_bind_data
after the line  "case PYTHON_FIXNUM:"
you can add the following code:
if (curr->data_type == SQL_BIGINT) {
   PyObject *temp_str;

   temp_str =  PyObject_Str(bind_data);
   curr->svalue = PyString_AsString(temp_str);
   curr->ivalue = strlen(curr->svalue);
   curr->bind_indicator = curr->ivalue;
   curr->svalue = memcpy(ALLOC_N(char, curr->ivalue+1), curr->svalue, curr->ivalue);
   Py_DecRef(temp_str);

   curr->svalue[curr->ivalue] = '\0';
   rc = SQLBindParameter(stmt_res->hstmt, curr->param_num,
   curr->param_type, SQL_C_CHAR, curr->data_type, curr->param_size,
   curr->scale, (SQLPOINTER)(curr->svalue), curr->ivalue, &(curr->bind_indicator));
   if ( rc == SQL_ERROR ) {
      _python_ibm_db_check_sql_errors(stmt_res->hstmt, SQL_HANDLE_STMT, 
                                            rc, 1, NULL, -1, 1);
   }
   curr->data_type = SQL_C_CHAR;
   break;
}

Original issue reported on code.google.com by [email protected] on 22 Jan 2009 at 3:15

Attachments:

Django backend sequence reset likely to fail in real-world situations

The implementation of sequence_reset_sql() in 
ibm_db_django/django/db/backends/db2/operations.py is extremely fragile. It 
assumes that fewer 
than 10,000 sequential values have been used from the sequence, which is highly 
likely to fail on 
real-world installations.

For a better implementation, consult the existing Django backends for 
PostgreSQL and Oracle, both 
of which select the maximum value in use and increment it to obtain an unused 
value to reset the 
sequence.

Original issue reported on code.google.com by [email protected] on 20 Jun 2009 at 7:04

sql select generation with TextField fields (Clobs) in where clause fails, e.g. django.contrib.comments

What steps will reproduce the problem?
1. install django.contrib.comments
2. create a comment for some other object
3. do Comment.objects.get(object_pk = id, content_type...)

What is the expected output? What do you see instead?
to be able to retrieve the object
but instead: SQL0401N  The data types of the operands for the operation "=" are 
not 
compatible or comparable.  SQLSTATE=42818

basically, the query that gets generated is select .. from django_comments 
where object_pk = 
'11'   and since object_pk is a TextField which gets generated as a Clob.  
would want the query to be varchar(object_pk) = '11' which would work



What version of the product are you using? On what operating system?
1.0, linux 2.6.31.5-127.fc12.i686  using db2 9.7 fixpack 1



Please provide any additional information below.



Original issue reported on code.google.com by [email protected] on 9 Dec 2009 at 8:31

It's not possible to distinguish between float (e.g. DOUBLE) and fixed (e.g. DECIMAL) point fields.

The function ibm_db_field_type is treating float (e.g. DOUBLE) and fixed 
(e.g. DECIMAL) point fields the same:

switch (stmt_res->column_info[col].type) {
...
        case SQL_REAL:
        case SQL_FLOAT:
        case SQL_DOUBLE:
        case SQL_DECIMAL:
        case SQL_NUMERIC:
        case SQL_DECFLOAT:
            str_val = "real";
            break;
...
}

So it is not possible to treat fixed point fields different from float 
point fields. This would be necessary if e.g. DECIMAL fields should be 
converted to a Python decimal.Decimal object and DOUBLE fields to a Python 
float.

Original issue reported on code.google.com by [email protected] on 18 Aug 2009 at 8:06

Error on connect w/Apache, Django, and mod_wsgi

We have a Django application that we are trying to host via Apache and
mod_wsgi.  The application fails to make a database connection when loading
any of the application pages.

What is the expected output? What do you see instead?
Connections to database should be made and the page should load with
information from the database.  

We see the following in the Apache error_log:
    self.connection = Database.connect (**kwargs)
  File
"/opt/python2.6.3/lib/python2.6/site-packages/ibm_db-1.0-py2.6-linux-x86_64.egg/
ibm_db_dbi.py",
line 436, in connect
    raise _get_exception(inst)
Error: ibm_db_dbi::Error: SystemError('error return without exception set',)

We have looked at client and server side traces and it doesn't appear to
have made any sort of connection to the database server.

What version of the product are you using? On what operating system?
RedHat Enterprise Linux 4.7, Python 2.6.3, Django 1.1, mod_wsgi 3.1,
ibm_db-1.0, IBM DB2 V9.1.7 client

Please provide any additional information below.
We can run the stand-alone httpd server (django manage.py runserver
127.0.0.1:8000) and the application connects to the database properly and
loads the data appropriately, so we know the database connections are
configured properly.

Original issue reported on code.google.com by [email protected] on 15 Dec 2009 at 3:45

PEP 249 requires autocommit to be initially off

Looking at the source of the 0.2.7 release, the connect method passes in
SQL_AUTOCOMMIT_ON if no autocommit option is specified in the connection
parameters. This is inconsistent with the requirements of PEP 249 (refer to
the documentation of the commit() method in the PEP).


Original issue reported on code.google.com by [email protected] on 21 Mar 2008 at 7:54

I got '<nil>' instead of a real value when I select a graphic column.

What steps will reproduce the problem?
1. DB2 CREATE TABLE TEST ( COL1 GRAPHIC(10) )
2. DB2 INSERT INTO TEST VALUES ( 'AAAA')
3.
import ibm_db
conn=ibm_db.connect
("DATABASE=dbname;HOSTNAME=hostname;PORT=50000;PROTOCOL=TCPIP;UID=userid;PW
D=password;", "", "")
sql = "SELECT COL1 FROM TEST"
stmt = ibm_db.exec_immediate(conn,sql)
dictionary = ibm_db.fetch_tuple(stmt)
while dictionary != False:
    print dictionary
    dictionary = ibm_db.fetch_tuple(stmt)


What is the expected output? What do you see instead?
expected : ('AAAA',)
showed : (<nil>,)

What version of the product are you using? On what operating system?
DB2 LUW V9.5.1 on Windows 2003 EE

Please provide any additional information below.
How can I see the value in the graphic column?


Original issue reported on code.google.com by [email protected] on 5 Feb 2009 at 2:44

db2 connect license

What steps will reproduce the problem?
connect to a db2 instance running on a os-400
>>> from sqlalchemy import *;
create_engine('ibm_db_sa://myuser:mypass@somehost:446/somedb').connect(

expected: 
<sqlalchemy.engine.base.Connection object at 0x830126c>

output:
sqlalchemy.exceptions.ProgrammingError: (ProgrammingError)
ibm_db_dbi::ProgrammingError: [IBM][CLI Driver] SQL8002N  An attempt to
connect to a host failed due to a missing DB2 Connect product or invalid
license.  SQLSTATE=42968 SQLCODE=-8002 None None

versions:
 * linux 2.6.22-14-server (ubuntu 7.10 gutsy)
 * ibm_db 0.2.5
 * ibm_db_sa 0.1.1
 * sqlalchemy 0.4.3
 * os-400 v5r3

I think a local db2 connect license is missing, but I'm not clear on what
license to get and if this will aleviate the problem.

Original issue reported on code.google.com by [email protected] on 16 Feb 2008 at 3:32

Variants of SQL_BINARY type are incorrectly truncated when returned in a result set

What steps will reproduce the problem?
1. Define a table with a CHAR(13) FOR BIT DATA COLUMN
2. Insert a few rows that have sequential zeroes. Ex:
x'20000103223021595898000000'
3. Select the data, and print it using pythons binascii.b2a_hex() method

What is the expected output? What do you see instead?
Expected: 20000103223021595898000000
Actual:   20


What version of the product are you using? On what operating system?
DB2 v9.5
ibm_db-1.0-py2.5-linux-i686.egg 
Python 2.5.5

Please provide any additional information below.
in ibm_db.c line 6567, PyString_FromString() is called on the str_val union
member, but that method detects a null byte as a string terminator, which
results in the data being truncated. 
Using PyString_FromStringAndSize() with the str_val, and the column_info
size reported by the CLI results in the correct value. 



I've attached the output of `svn diff' as proof-of-concept, but I'm not
sure what implications it might have. It did solve the immediate problem.  

All of our tables use CHAR(13) FOR BIT DATA as the primary key, so this is
a significant problem. 

Original issue reported on code.google.com by [email protected] on 1 Mar 2010 at 9:39

Attachments:

django: Reading LONG VARCHAR columns - adapter saves ok, but reads only first character

I have existing table in db which is declared as LONG VARCHAR (no length
defined, default is 32700).

I mapped this to django TextField with no length models.TextField(). 

But when data is read from the table only first character is retrieved. 
Saving data to this column 
Example:

class Table(models.Model):
    data = models.TextField(_('data'))

>>> Table.objects.create(data="test")
>>> Table.objects.all()[0].data=="t"
True

Saving to db went ok, since in table is really "test" data, but fetching
from table returns only "t".

Original issue reported on code.google.com by [email protected] on 5 Jan 2010 at 4:31

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.