#31 method to set an existing mysql connection for all scripts

MySQLdb
open
MySQLdb (53)
5
2012-09-19
2006-03-07
David Faure
No

MySQLdb is currently designed to open MYSQL
connections by itself. However when using python
embedded into a C program, we might want python
scripts to use an existing MYSQL connection,
established by the hosting C program. One reason is
the case where scripts should execute within the
context of a transaction set up by the hosting
program.

This patch adds a setGlobalMySQLConnection function
which the hosting application can call with a MYSQL*
pointer which will then be used by any
_mysql_ConnectionObject instance.

One problem is that I don't know how to stuff a
MYSQL (i.e. a void) into a PyObject so I used a
long int. Should work in all cases though since long
and void* have the same size on all system.

The other issue is that the _mysql_ConnectionObject
struct needed to be changed to hold a MYSQL* instead
of a MYSQL, but this broke the
"offsetof(connection.port)" construct, so I
duplicated the port/server_capabilities/client_flag
values into the struct, but I guess one could also
get rid of the offsetof mechanism? Anyway, it works
this way.

Discussion

  • David Faure

    David Faure - 2006-03-07

    setGlobalMySQLConnection patch

     
  • Andy Dustman

    Andy Dustman - 2006-03-07

    Logged In: YES
    user_id=71372

    I can't get this into 1.2.1, but probably 1.3.

    What I will probably end up having is a Connection object
    class method which creates a new Connection object using the
    given pointer.

    Plus, you're using C++ comments in C. Naughty.

     
  • David Faure

    David Faure - 2006-03-09

    Logged In: YES
    user_id=591851

    Adding a Connection object class method means that the
    calling code would have to be changed in order to create
    Connections differently, right? This would make things more
    complicated when using e.g. SQLObject. With
    setGlobalMySQLConnection the upper layer doesn't have to be
    changed.

    Sorry for the C++-like comments, I'm a C++ developer not
    really used to writing C code, and gcc said nothing :)

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks