Re: trouble installing MySQLdb (cygwin) + Bonus question

2011-01-26 Thread John Nagle

On 1/25/2011 3:51 PM, Matthew Roth wrote:

On Jan 25, 6:20 pm, David Robinowdrobi...@gmail.com  wrote:

On Tue, Jan 25, 2011 at 5:59 PM, Matthew Rothmgrot...@gmail.com  wrote:

On Jan 25, 9:34 pm, John Naglena...@animats.com  wrote:

...

 You can install a MySQL server under Windows, and talk to the server
from the Cygwin environment.  That's a useful way to test.



 John Nagle



Right, that is precisely what I have. I am able to talk to it from
cygwin, however, during the installing of the MySQLdb module it cannot
find the mysql_config. This is because It is not installed? The setup
sees that I am on a posix system not windows, as python is installed
in cygwin, a virtual posix system. I am trying to bulid a mysql client
from source for cygwin, however, I am running into an error there.



Unless, can I talk to the windows mysql_config? if so, what does that
look like


  The obvious answer is to use a Windows python. You haven't explained
why you think you need to run a cygwin python. Can you explain that?



Good question. There isn't a solid explanation. heretofore, I have
been using a lot of bash scripting in combination with awk sed and
some perl. I was directed to look into python. My tasks were becoming
increasingly complex and memory intensive. I started with a desire to
connect to a mysql server. For that I needed to install the MySQLdb
module. I am having difficultly in acomplishment of this task. I
suppose for the time it has taken, using windows python would have
been the simpler route.


   Oh.  And all this time, I thought it was because you needed to
run on a Linux server and were using Cygwin for debugging.

   I routinely develop Python on Windows and run on Linux servers.
This works fine, provided that you can find versions of any necessary C
modules for Python for both platforms.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


Re: trouble installing MySQLdb (cygwin) + Bonus question

2011-01-25 Thread Matthew Roth
On Jan 25, 4:30 am, Dennis Lee Bieber wlfr...@ix.netcom.com wrote:
 On Mon, 24 Jan 2011 14:25:09 -0800 (PST), Matthew Roth
 mgrot...@gmail.com declaimed the following in
 gmane.comp.python.general:



  I've explored various avenues all day to no avail. Can anyone offer a
  solution or a direction to work towards. One avenue was ignorning the
  check for posix, and having it run setup_windows, but this just brings
  in problems with _winreg(?) seeing how I have a posix version of
  python through cygwin.

         Maybe you need the development headers for MySQL?
--
I do believe I have them. Perhaps I need to find the correct way to
point to them.
I believe it is looking for the dev headers for a linux client when I
am using a client for windows via cygwin.

Or perhaps I should look into installing a separate linux mysql client
in cygwin.
I read of a similiar problem with perl, but the documentation felt a
bit dated and several steps would no longer function correctly.


  Lastly, for the bonus question.
  Why MySQLdb why not something like this:
  --
  import os
  cmd = 'mysql -uroot -pxxx db -e SELECT * FROM tblxxx;'
  os.system(cmd)

         Passing username/password to a shell command that might be parsed by
 some outside process? Security leak!
--
I do indeed see that. However, all my python calls will be done within
my local intranet.
But is this a reason to not use os module at all? fetching a
dirlisting or mkdir is still
a valid reason to use the os Module, correct?

         Second -- MySQL is a server model DBMS; it doesn't have to be on the
 local machine.
--
unfortunately, for my use it does. We do have an old centOs box here,
but the mysql running on that is severely outdated and so too is the
python.
I have been discouraged from upgrading the former, and the latter I
was told only if I could do it through yum. Making an altinstall form
source seems to be
discouraged. Good news is I think they have decided to upgrade our
development box.

         Third -- ever heard of TRANSACTIONS? How would you handle a
 transaction if every SQL statement was a totally independent process?
 --
No. quite to my embarrassment I haven't. But this is not to say I have
not used them. It sounds as if I have.
But, you can put more than one sql statement into a cmdline.
mysql = mysql -uuser -ppass db -e \SELECT CURTIME();
   CREATE TABLE tempTBL (
   freq INT,
   x INT,
   y VARCHAR(255),
   PRIMARY KEY(x, y);

   LOAD XML INFLE 'doc'
   INTO TABLE tempTBL
   ROWS IDENTIFIED BY 'line';

   INSERT INTO freqTbl(x,y,freq)
   SELECT x,y,freq FROM tempTBL
   ON DUPLICATE KEY UPDATE freq=tempTbl.freq+freqTbl.freq;

   SELECT CURTIME();\
os.system(mysql)

I haven't tested that, but I know it works at the command line.
I do fully intend to use MySQLdb through python and conduct more of
the processing and parsing in python. It will be a learning
experience. I have a background in anthropology, not computer science.
But I love learning all this, and love that my place of employment
encourages me to learn this. Unfortunately with self-learning you can
sometimes miss out on important concepts and still accomplish tasks.

Thank you for your reply.


         Wulfraed                 Dennis Lee Bieber         AF6VN
         wlfr...@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble installing MySQLdb (cygwin) + Bonus question

2011-01-25 Thread Nitin Pawar
Nothing againest mysqlDB but I had tried using it sometimes and found it
little difficult to use when you left the connections open idle for sometime
.

I had used PySQLPool then to solve my issues.

Give it a try, I would recommend it.

Thanks,
nitin

On Tue, Jan 25, 2011 at 8:35 PM, Matthew Roth mgrot...@gmail.com wrote:

 On Jan 25, 4:30 am, Dennis Lee Bieber wlfr...@ix.netcom.com wrote:
  On Mon, 24 Jan 2011 14:25:09 -0800 (PST), Matthew Roth
  mgrot...@gmail.com declaimed the following in
  gmane.comp.python.general:
 
 
 
   I've explored various avenues all day to no avail. Can anyone offer a
   solution or a direction to work towards. One avenue was ignorning the
   check for posix, and having it run setup_windows, but this just brings
   in problems with _winreg(?) seeing how I have a posix version of
   python through cygwin.
 
  Maybe you need the development headers for MySQL?
 --
 I do believe I have them. Perhaps I need to find the correct way to
 point to them.
 I believe it is looking for the dev headers for a linux client when I
 am using a client for windows via cygwin.

 Or perhaps I should look into installing a separate linux mysql client
 in cygwin.
 I read of a similiar problem with perl, but the documentation felt a
 bit dated and several steps would no longer function correctly.

 
   Lastly, for the bonus question.
   Why MySQLdb why not something like this:
   --
   import os
   cmd = 'mysql -uroot -pxxx db -e SELECT * FROM tblxxx;'
   os.system(cmd)
 
  Passing username/password to a shell command that might be parsed
 by
  some outside process? Security leak!
 --
 I do indeed see that. However, all my python calls will be done within
 my local intranet.
 But is this a reason to not use os module at all? fetching a
 dirlisting or mkdir is still
 a valid reason to use the os Module, correct?
 
  Second -- MySQL is a server model DBMS; it doesn't have to be on
 the
  local machine.
 --
 unfortunately, for my use it does. We do have an old centOs box here,
 but the mysql running on that is severely outdated and so too is the
 python.
 I have been discouraged from upgrading the former, and the latter I
 was told only if I could do it through yum. Making an altinstall form
 source seems to be
 discouraged. Good news is I think they have decided to upgrade our
 development box.
 
  Third -- ever heard of TRANSACTIONS? How would you handle a
  transaction if every SQL statement was a totally independent process?
  --
 No. quite to my embarrassment I haven't. But this is not to say I have
 not used them. It sounds as if I have.
 But, you can put more than one sql statement into a cmdline.
 mysql = mysql -uuser -ppass db -e \SELECT CURTIME();
   CREATE TABLE tempTBL (
   freq INT,
   x INT,
   y VARCHAR(255),
   PRIMARY KEY(x, y);

   LOAD XML INFLE 'doc'
   INTO TABLE tempTBL
   ROWS IDENTIFIED BY 'line';

   INSERT INTO freqTbl(x,y,freq)
   SELECT x,y,freq FROM tempTBL
   ON DUPLICATE KEY UPDATE freq=tempTbl.freq+freqTbl.freq;

   SELECT CURTIME();\
 os.system(mysql)

 I haven't tested that, but I know it works at the command line.
 I do fully intend to use MySQLdb through python and conduct more of
 the processing and parsing in python. It will be a learning
 experience. I have a background in anthropology, not computer science.
 But I love learning all this, and love that my place of employment
 encourages me to learn this. Unfortunately with self-learning you can
 sometimes miss out on important concepts and still accomplish tasks.

 Thank you for your reply.


  Wulfraed Dennis Lee Bieber AF6VN
  wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/

 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Nitin Pawar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble installing MySQLdb (cygwin) + Bonus question

2011-01-25 Thread Matthew Roth
Thank you. I appreciate you explanation and tolerance of my
ignorance.

However unfortunate, this still does not solve my major issue.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble installing MySQLdb (cygwin) + Bonus question

2011-01-25 Thread John Nagle

On 1/25/2011 7:05 AM, Matthew Roth wrote:

On Jan 25, 4:30 am, Dennis Lee Bieberwlfr...@ix.netcom.com  wrote:

On Mon, 24 Jan 2011 14:25:09 -0800 (PST), Matthew Roth
mgrot...@gmail.com  declaimed the following in
gmane.comp.python.general:



 Second -- MySQL is a server model DBMS; it doesn't have to be on the
local machine.

--
unfortunately, for my use it does. We do have an old centOs box here,
but the mysql running on that is severely outdated and so too is the
python.


   You can install a MySQL server under Windows, and talk to the server
from the Cygwin environment.  That's a useful way to test.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


Re: trouble installing MySQLdb (cygwin) + Bonus question

2011-01-25 Thread Matthew Roth
On Jan 25, 9:34 pm, John Nagle na...@animats.com wrote:
 On 1/25/2011 7:05 AM, Matthew Roth wrote:

  On Jan 25, 4:30 am, Dennis Lee Bieberwlfr...@ix.netcom.com  wrote:
  On Mon, 24 Jan 2011 14:25:09 -0800 (PST), Matthew Roth
  mgrot...@gmail.com  declaimed the following in
  gmane.comp.python.general:
           Second -- MySQL is a server model DBMS; it doesn't have to be on 
  the
  local machine.
  --
  unfortunately, for my use it does. We do have an old centOs box here,
  but the mysql running on that is severely outdated and so too is the
  python.

     You can install a MySQL server under Windows, and talk to the server
 from the Cygwin environment.  That's a useful way to test.

                                         John Nagle

Right, that is precisely what I have. I am able to talk to it from
cygwin, however, during the installing of the MySQLdb module it cannot
find the mysql_config. This is because It is not installed? The setup
sees that I am on a posix system not windows, as python is installed
in cygwin, a virtual posix system. I am trying to bulid a mysql client
from source for cygwin, however, I am running into an error there.

Unless, can I talk to the windows mysql_config? if so, what does that
look like

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble installing MySQLdb (cygwin) + Bonus question

2011-01-25 Thread David Robinow
On Tue, Jan 25, 2011 at 5:59 PM, Matthew Roth mgrot...@gmail.com wrote:
 On Jan 25, 9:34 pm, John Nagle na...@animats.com wrote:
...
     You can install a MySQL server under Windows, and talk to the server
 from the Cygwin environment.  That's a useful way to test.

                                         John Nagle

 Right, that is precisely what I have. I am able to talk to it from
 cygwin, however, during the installing of the MySQLdb module it cannot
 find the mysql_config. This is because It is not installed? The setup
 sees that I am on a posix system not windows, as python is installed
 in cygwin, a virtual posix system. I am trying to bulid a mysql client
 from source for cygwin, however, I am running into an error there.

 Unless, can I talk to the windows mysql_config? if so, what does that
 look like
 The obvious answer is to use a Windows python. You haven't explained
why you think you need to run a cygwin python. Can you explain that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble installing MySQLdb (cygwin) + Bonus question

2011-01-25 Thread Matthew Roth
On Jan 25, 6:20 pm, David Robinow drobi...@gmail.com wrote:
 On Tue, Jan 25, 2011 at 5:59 PM, Matthew Roth mgrot...@gmail.com wrote:
  On Jan 25, 9:34 pm, John Nagle na...@animats.com wrote:
 ...
      You can install a MySQL server under Windows, and talk to the server
  from the Cygwin environment.  That's a useful way to test.

                                          John Nagle

  Right, that is precisely what I have. I am able to talk to it from
  cygwin, however, during the installing of the MySQLdb module it cannot
  find the mysql_config. This is because It is not installed? The setup
  sees that I am on a posix system not windows, as python is installed
  in cygwin, a virtual posix system. I am trying to bulid a mysql client
  from source for cygwin, however, I am running into an error there.

  Unless, can I talk to the windows mysql_config? if so, what does that
  look like

  The obvious answer is to use a Windows python. You haven't explained
 why you think you need to run a cygwin python. Can you explain that?


Good question. There isn't a solid explanation. heretofore, I have
been using a lot of bash scripting in combination with awk sed and
some perl. I was directed to look into python. My tasks were becoming
increasingly complex and memory intensive. I started with a desire to
connect to a mysql server. For that I needed to install the MySQLdb
module. I am having difficultly in acomplishment of this task. I
suppose for the time it has taken, using windows python would have
been the simpler route.


Anyway, I have done some tinkering and have moved passed the
mysql_config problem. Thanks to Davids reminder that I have mysql on
windows. Meaning when setup.py called setup_posix.py It was
essentially calling mysql_config. Well mysql_config was in a far off
folder. I setup a symbolic link and that worked. However I was then
presented with a new problem. In direct relation to that far off
folder. Dreaded spaces. (i headed the log)

--
 running build
 running build_py
 copying MySQLdb/release.py - build/lib.cygwin-1.7.7-i686-2.6/MySQLdb
 running build_ext
 building '_mysql' extension
 creating build/temp.cygwin-1.7.7-i686-2.6
 gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-
prototypes -Dversion_info=(1,2,3,'final'
 ,0) -D__version__=1.2.3 -I/usr/include/python2.6 -c _mysql.c -o build/
temp.cygwin-1.7.7-i686-2.6/_mysql.
 o -I/cygdrive/c/Program Files/MySQL/MySQL Server 5.5/include /MT
/Zi /O2 /Ob1 /D NDEBUG -
 DDBUG_OFF
 gcc: -I/cygdrive/c/Program: No such file or directory
--

there is much more, but obviously the problem is  gcc: -I/cygdrive/c/
Program: No such file or directory

what I need to do is have it point to /cygdrive/c/Program\ Files/MySQL/
MySQL\ Server\ 5.5/include and not cygdrive/c/Program Files/MySQL/
MySQL Server 5.5/include.

I am currently trying to track that down. I think I am going to leave
work and go grab some dinner. perhaps I will solve this later tonight.

Best,
Matt

-- 
http://mail.python.org/mailman/listinfo/python-list


trouble installing MySQLdb (cygwin) + Bonus question

2011-01-24 Thread Matthew Roth
Hi,
I'm a python newbie. By newbie I mean two days ago.
It was suggested to me that I work with python.
Unfortunately at work I must run this on a windows machiene.

However, I am having difficultly installing MySQLdb.

First is it even possible under my current environment?
I am using python(2.6.5) through cygwin, and have mySQL(Ver 14.14
Distrib 5.5.8 for Win32) installed in windows 7

which mysql returns:
/cygdrive/c/Program Files/MySQL/MySQL Server 5.5/bin/mysql

when I run
python setup.py build it returns:
--
$ python setup.py build
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File setup.py, line 15, in module
metadata, options = get_config()
File /home/Matt/MySQL-python-1.2.3/setup_posix.py, line 43, in
get_config
libs = mysql_config(libs_r)
File /home/Matt/MySQL-python-1.2.3/setup_posix.py, line 24, in
mysql_config
raise EnvironmentError(%s not found % (mysql_config.path,))
EnvironmentError: mysql_config not found
--

I've explored various avenues all day to no avail. Can anyone offer a
solution or a direction to work towards. One avenue was ignorning the
check for posix, and having it run setup_windows, but this just brings
in problems with _winreg(?) seeing how I have a posix version of
python through cygwin.

Lastly, for the bonus question.
Why MySQLdb why not something like this:
--
import os
cmd = 'mysql -uroot -pxxx db -e SELECT * FROM tblxxx;'
os.system(cmd)

--

why is this a poor idea?

Best,
Matt
-- 
http://mail.python.org/mailman/listinfo/python-list


Trouble with MySQLdb

2009-09-15 Thread Chris
I'm receiving the following error:



Traceback (most recent call last):
  File db.py, line 189, in module
rows = db.get(SELECT * FROM survey)
  File db.py, line 55, in get
self.sql(query)
  File db.py, line 47, in sql
return self.cursor.execute(query)
  File build/bdist.linux-i686/egg/MySQLdb/cursors.py, line 168, in
execute
  File build/bdist.linux-i686/egg/MySQLdb/cursors.py, line 73, in
_warning_check
SystemError: null argument to internal routine



Here's the source for the db.py file:



#!/usr/bin/env python

import MySQLdb
import MySQLdb.cursors



#
# MySQL Abstraction Layer
#

class MySQL:
MySQL Abstraction Layer
connection  = None
cursor  = None
db  = None

def __init__(self, host = 'localhost', usr = 'user', pwd = 'pass',
db = 'main'):
if host:
self.connect(host, usr, pwd, db)

def connect(self, host, usr, pwd, db):
self.connection = MySQLdb.connect(host, usr, pwd, db,
unix_socket='/opt/lampp/var/mysql/mysql.sock',
cursorclass = MySQLdb.cursors.DictCursor)
self.cursor = self.connection.cursor()
self.db = db

##

def sql(self, query):
return self.cursor.execute(query)

def next(self):
return self.cursor.fetchone()

##

def get(self, query, pkey = None):
self.sql(query)
if not pkey:
ret = []
for i in self.cursor:
ret.append(i)
return ret

def row(self, query):
self.sql(query)
for i in self.cursor:
return i
return None

def field(self, query):
ret = []
self.sql(query)
for i in self.cursor:
ret.append(i[0])
return ret

def value(self, query):
self.sql(query)
for i in self.cursor:
return i[0]
return None

##

def getFields(self, table):
rows = self.get(DESCRIBE ` + table + `)
return [str(i[0]) for i in rows]

def getPrimaryKey(self, table):
rows = self.get(DESCRIBE ` + table + `)
return [str(i[0]) for i in rows if i[3] == 'PRI']



db = MySQL()
rows = db.get(SELECT * FROM survey)

for i in rows:
print i

raise SystemExit
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: some trouble with MySQLdb

2005-06-30 Thread dimitri pater
try:
db = MySQLdb.connect(host=localhost, user=user, passwd=pass,
db=myDB)
localhost can be a URL also (if MySQL is set up properly in the first place)
regards,
DimtiriOn 6/30/05, nephish [EMAIL PROTECTED] wrote:
Hey there all,i have a question about how to point my python install to my sql database.when i enter this: db = MySQLdb.connect(user=user, passwd=pass,db=myDB)i get this:
Traceback (most recent call last):File pyshell#1, line 1, in -toplevel-db = MySQLdb.connect(user=user, passwd=pass, db=MyDB)File /usr/lib/python2.4/site-packages/MySQLdb/__init__.py, line 66,
in Connectreturn Connection(*args, **kwargs)File /usr/lib/python2.4/site-packages/MySQLdb/connections.py, line134, in __init__super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1049, Unknown database 'MyDB')i am using the all in one package from lampp (now xampp) and i havetested a couple of python scripts from the cgi, but nothing thatconnects to the database.
any ideas?thanks--http://mail.python.org/mailman/listinfo/python-list-- Please visit dimitri's website: 
www.serpia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

some trouble with MySQLdb

2005-06-29 Thread nephish
Hey there all,
i have a question about how to point my python install to my sql database.

when i enter this: db = MySQLdb.connect(user=user, passwd=pass, 
db=myDB)

i get this:
Traceback (most recent call last):
  File pyshell#1, line 1, in -toplevel-
db = MySQLdb.connect(user=user, passwd=pass, db=MyDB)
  File /usr/lib/python2.4/site-packages/MySQLdb/__init__.py, line 66, 
in Connect
return Connection(*args, **kwargs)
  File /usr/lib/python2.4/site-packages/MySQLdb/connections.py, line 
134, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1049, Unknown database 'MyDB')

i am using the all in one package from lampp (now xampp) and i have 
tested a couple of python scripts from the cgi, but nothing that 
connects to the database.

any ideas?

thanks
-- 
http://mail.python.org/mailman/listinfo/python-list