CUBRID Python Tutorial
– Part I (2010)

The scope of this tutorial is to give
you a quick introduction to the CUBRID Python driver. The first part of this tutorial will explain the
steps you need to perform in order to connect to the CUBRID database and to run
SQL statements using Python.

Also, the standard demodb
database is required for the code examples – we will assume it is already installed
on your environment. And we will use CUBRID 9.0 in the examples below – you can
always download the latest version from here: http://www.cubrid.org/downloads.

Start the demodb database

Once the Python driver is installed, let’s make sure that the demodb database is started.

In the previous
versions of the driver, the auto-commit in the CUBRID Python Driver
was disabled by default. Therefore after we executed any SQL statement we had
to manually call the .commit() command.

But in the current driver version, this is
not required anymore, as the auto-commit state is enabled by default.

As a side note, commit()is equivalent to
executing cur.execute("COMMIT").
And the opposite to commit() is
the rollback() method
which aborts the current transaction, equivalent to cur.execute("ROOLBACK").

Another way to insert the data is to execute
the prepared INSERT statements; this is the recommended method of
inserting data into a table. We can do this by defining a tuple that contains
the parameters and pass it to the execute
method, as follows:

In a scenario where a lot of data must be returned into the cursor,
you have also the possibility to fetch just only one row at a time from the
database, instead of getting all the result set into memory, by using fetchone().

Access records metadata

If you need to get information about column properties for the returned
records, this is what you need to do – use description: