Python and MySQL

A

Aquarius

I appologize in advance for this strange (and possibly stupid)
question.

I want to know if there is a way to interface a MySQL database without
Python-MySQL or without installing anything that has C files that need
to be compiled. The reason for this, is that I want to develop a
certain web application, but my hosting provider (!#@$!@#%) isn't very
eager to supply Python-MySQL (or any modules to python). Is there an
alternative approach I could use to pass around this ridiculos lack of
functionality?
 
A

Alan Kennedy

[Aquarius]
I appologize in advance for this strange (and possibly stupid)
question.

I want to know if there is a way to interface a MySQL database without
Python-MySQL or without installing anything that has C files that need
to be compiled. The reason for this, is that I want to develop a
certain web application, but my hosting provider (!#@$!@#%) isn't very
eager to supply Python-MySQL (or any modules to python). Is there an
alternative approach I could use to pass around this ridiculos lack of
functionality?

Possibly not want you want to hear, but I'd strongly recommend to stop
wasting your time with a hosting company that doesn't support the
technologies you need.

Instead, try a hosting company that supports python: there are lots and lots

http://wiki.python.org/moin/PythonHosting

Life's too short to spend your time hacking around artificial barriers
to progress.
 
S

Steve Holden

Aquarius said:
I appologize in advance for this strange (and possibly stupid)
question.

I want to know if there is a way to interface a MySQL database without
Python-MySQL or without installing anything that has C files that need
to be compiled. The reason for this, is that I want to develop a
certain web application, but my hosting provider (!#@$!@#%) isn't very
eager to supply Python-MySQL (or any modules to python). Is there an
alternative approach I could use to pass around this ridiculos lack of
functionality?
You'll definitely need something to call the database API functions, I
suspect.

You could do a *private* install of the module though, surely, on your
web host?

regards
Steve
 
M

Magnus Lycka

Aquarius said:
I appologize in advance for this strange (and possibly stupid)
question.

I want to know if there is a way to interface a MySQL database without
Python-MySQL or without installing anything that has C files that need
to be compiled. The reason for this, is that I want to develop a
certain web application, but my hosting provider (!#@$!@#%) isn't very
eager to supply Python-MySQL (or any modules to python). Is there an
alternative approach I could use to pass around this ridiculos lack of
functionality?

I assume that MySQL clients talk to servers via sockets, and it should
be possible to write a python client that did that. It's probably some
work though, and it will probably piss MySQL AB off, since it means that
you could write MySQL client apps using whatever license you want
without paying them.

I wrote a prototype for such a client lib for PostgreSQL once, and it
was fairly simple, but the PostgreSQL docs have decent descriptions of
their protocol, while I assume MySQL hasn't since they want people to
use their client libs and pay for that. (If you read the client lib
source and translate that to Python, it should be considered a derivate,
and GPL applies. If you manage to get it to work without reading any
GPLed code, I guess you are entitled to use whatever license you want.)


Disclaimer: IANAL.
 
T

Thomas Bartkus

Aquarius said:
I appologize in advance for this strange (and possibly stupid)
question.

I want to know if there is a way to interface a MySQL database without
Python-MySQL or without installing anything that has C files that need
to be compiled. The reason for this, is that I want to develop a
certain web application, but my hosting provider (!#@$!@#%) isn't very
eager to supply Python-MySQL (or any modules to python). Is there an
alternative approach I could use to pass around this ridiculos lack of
functionality?

Well, I'm looking at the source for the ever popular MySQLdb library. It
appears to be nothing but straight up Python source code. I see no reason
why you couldn't just take these modules and put them in your own private
directory. There is nothing secret here.

But

As others have already pointed out, after you go to this trouble, your
hosting provider will still suck! I'm sure you can you can get lot's of
suggestions for a suitable replacement.

Thomas Bartkus
 
S

Steve Holden

Thomas said:
Well, I'm looking at the source for the ever popular MySQLdb library. It
appears to be nothing but straight up Python source code. I see no reason
why you couldn't just take these modules and put them in your own private
directory. There is nothing secret here.

But

As others have already pointed out, after you go to this trouble, your
hosting provider will still suck! I'm sure you can you can get lot's of
suggestions for a suitable replacement.
I have a _mysql.c as a part of my distrbution of MySQLdb. Don't you?

regards
Steve
 
T

Thomas Bartkus

Steve Holden said:
I have a _mysql.c as a part of my distrbution of MySQLdb. Don't you?

You made me give that library a good hard stare.

And no - everything is enunciated in clear Python (.py) code with
corresponding (.pyc) and (.pyo). It appears we have Python source for
everything.

FWIW:
(1, 2, 0, 'final', 1)

There doesn't seem to be .c code to be found anywhere.
Thomas Bartkus
 
S

Steve Holden

Thomas said:
You made me give that library a good hard stare.

And no - everything is enunciated in clear Python (.py) code with
corresponding (.pyc) and (.pyo). It appears we have Python source for
everything.

FWIW:



(1, 2, 0, 'final', 1)
OK. I saw that my own version was (1, 0, 0, 'final', 1), so I assumed
Andy's updated the package somewhat. However, downloading the source of
1.2 I see that _mysql.c still appears, and that the package's
__init__.py still includes the line

include _mysql

My C:\Python24\Lib\site-packages directory does contain a _mylsql.pyd
file. Would you like to check that we are talking about the same module?

regards
Steve
 
S

Sion Arrowsmith

Aquarius said:
I want to know if there is a way to interface a MySQL database without
Python-MySQL or without installing anything that has C files that need
to be compiled. The reason for this, is that I want to develop a
certain web application, but my hosting provider (!#@$!@#%) isn't very
eager to supply Python-MySQL (or any modules to python). Is there an
alternative approach I could use to pass around this ridiculos lack of
functionality?

If you've got MySQL installed, you probably have a command-line
mysql client, and you could use subprocess or popen to run that.
That's a little desperate though, and the error handling will suck.
(I've seen this trick used with other databases.)
 
T

Thomas Bartkus

Steve Holden said:
OK. I saw that my own version was (1, 0, 0, 'final', 1), so I assumed
Andy's updated the package somewhat. However, downloading the source of
1.2 I see that _mysql.c still appears, and that the package's
__init__.py still includes the line

include _mysql

My C:\Python24\Lib\site-packages directory does contain a _mylsql.pyd
file. Would you like to check that we are talking about the same module?

Okay - I neglected to look at the [site-packages] directory itself. Here I
do find [_mysql.pyd] full of binary code. A MySQLdb related file that
doesn't seem to have a corresponding file with Python source code. Mea
culpa! This is on MS Windows [C:\Python23].

But heck! Now I'm looking at the /usr/lib/python2.3/site-packages on a
Mandrake Linux box. No [_mysql.] pyd here! Fewer files overall and while
there are other file extensions, everything seems to have a corresponding
[.py].

print MySQLdb.version_info
(0, 9, 2, 'final', 1)

Thomas Bartkus
 
M

Magnus Lycka

Thomas said:
But heck! Now I'm looking at the /usr/lib/python2.3/site-packages on a
Mandrake Linux box. No [_mysql.] pyd here! Fewer files overall and while
there are other file extensions, everything seems to have a corresponding
[.py].

I suspect you might find _mysql.so there. If you find any .pyd files I
think you can safely remove them, since Windows DLLs work poorly in
Linux anyway. Aren't you starting to suspect that you don't really know
what you are talking about in this particular case? Where is the pure
Python code that actually communicates with the database server? Have
you found a single line of code that actually does that? How does it
communicate? Isn't there an 'import _mysql' somewhere? Where is the
_mysql.py then?

What's this?
http://cvs.sourceforge.net/viewcvs.py/mysql-python/MySQLdb/_mysql.c

What's this doing in setup.py?
'ext_modules': [
Extension(
name='_mysql',
sources=['_mysql.c'],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_objects=extra_objects,
),
],
 
?

=?ISO-8859-1?Q?Gerhard_H=E4ring?=

Thomas said:
[some posters having the idea that MySQLdb works without a C extension]
Okay - I neglected to look at the [site-packages] directory itself. Here I
do find [_mysql.pyd] full of binary code. A MySQLdb related file that
doesn't seem to have a corresponding file with Python source code. Mea
culpa! This is on MS Windows [C:\Python23].

But heck! Now I'm looking at the /usr/lib/python2.3/site-packages on a
Mandrake Linux box. No [_mysql.] pyd here! Fewer files overall and while
there are other file extensions, everything seems to have a corresponding
[.py].

MySQLdb is based on a C extension module called _mysql on all platforms.
The C extension modules have the extension ".pyd" on Windows by default,
and ".so" on Unix.

It would in theory be possible to do without a C extension, but then you
would have to implement the MySQL client-server protocol
(http://dev.mysql.com/doc/internals/en/client-server-protocol.html) in
Python, for example using the socket module.

Implementing a pure-Python package to interface a database by
implementing the client-server protocol in Python has been done already
for PostgreSQL, but I don't think it has been done for MySQL, yet.

-- Gerhard
 
T

Thomas Bartkus

Magnus Lycka said:
Thomas said:
But heck! Now I'm looking at the /usr/lib/python2.3/site-packages on a
Mandrake Linux box. No [_mysql.] pyd here! Fewer files overall and while
there are other file extensions, everything seems to have a corresponding
[.py].

I suspect you might find _mysql.so there. If you find any .pyd files I
think you can safely remove them, since Windows DLLs work poorly in
Linux anyway. Aren't you starting to suspect that you don't really know
what you are talking about in this particular case?

Yes!

And thank you so much for pointing that out :)
Thomas Bartkus
Where is the pure
Python code that actually communicates with the database server? Have
you found a single line of code that actually does that? How does it
communicate? Isn't there an 'import _mysql' somewhere? Where is the
_mysql.py then?

What's this?
http://cvs.sourceforge.net/viewcvs.py/mysql-python/MySQLdb/_mysql.c

What's this doing in setup.py?
'ext_modules': [
Extension(
name='_mysql',
sources=['_mysql.c'],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_objects=extra_objects,
),
],
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,270
Messages
2,571,339
Members
48,029
Latest member
Anchorman2022

Latest Threads

Top