Thread: [Sqlrelay-discussion] Problem with Python cPickle and blobs
Brought to you by:
mused
From: Ville S. <vs...@eb...> - 2005-07-21 11:31:25
|
Hi, I'm using PySQLRClient from sqlrelay-0.36 (with rudiments-0.28.2) to store blobs in Oracle 9.2.0 database. I'm not sure if this has been fixed in the recent sqlrelay release, but I'm experiencing problems when I store a Python data structure (dictionary object) to a blob using Pythons cPickle module. Everything works great until one of the values in the pickled object is an empty string (''). After that cPickle.load fails to read the data, it raises EOFError exception. So I wonder if PySQLRClient interprets the pickled '' as an end-of-file character? If I try loading/saving similar data structure to a file, it works ok. Thanks for any advice, Ville |
From: Firstworks/4access <dav...@fi...> - 2005-07-21 13:42:29
|
Ville, I was actually looking at that last night. I'm believe you're on track. inputBind() does a strlen() of the string to decide how many characters to store in the database. strlen() interprets \0's as end-of-string markers, so only part of the data gets stored in the blob. Then, later when you fetch and unpickle it, only part of it gets unpickled. I believe the solution is to use inputBindBlob() or inputBindClob() rather than inputBind() to store the pickled data. inputBindBlob() and inputBindClob() take a length parameter and ignore \0's. Give it a try and let me know whether it works or not. Dave dav...@fi... On Thu, 2005-07-21 at 12:31 +0100, Ville Silventoinen wrote: > Hi, > > I'm using PySQLRClient from sqlrelay-0.36 (with rudiments-0.28.2) > to store blobs in Oracle 9.2.0 database. > > I'm not sure if this has been fixed in the recent sqlrelay release, > but I'm experiencing problems when I store a Python data structure > (dictionary object) to a blob using Pythons cPickle module. Everything > works great until one of the values in the pickled object is an empty > string (''). After that cPickle.load fails to read the data, it raises > EOFError exception. So I wonder if PySQLRClient interprets the pickled > '' as an end-of-file character? > > If I try loading/saving similar data structure to a file, it works ok. > > Thanks for any advice, > > Ville > > > > > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > from IBM. Find simple to follow Roadmaps, straightforward articles, > informative Webcasts and more! Get everything you need to get up to > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > _______________________________________________ > Sqlrelay-discussion mailing list > Sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > |
From: Ville S. <vs...@eb...> - 2005-07-21 13:51:52
|
Hi Dave, thanks for replying so quickly. Unfortunately I am already using the sqlrcursor.inputBindBlob. I also pass the length parameter, which I get by calling Python len function: sdata = cPickle.dumps(data) slen = len(sdata) Could len give a wrong length? I will do some tests. I have also tried "cPickle,dumps(data, 2)" as well, same problem. I have avoided the problem now by using None instead of '' values. That seems to work fine. Thanks, Ville On Thu, 21 Jul 2005, Firstworks/4access wrote: > Ville, > > I was actually looking at that last night. I'm believe you're on track. > inputBind() does a strlen() of the string to decide how many characters > to store in the database. strlen() interprets \0's as end-of-string > markers, so only part of the data gets stored in the blob. Then, later > when you fetch and unpickle it, only part of it gets unpickled. I > believe the solution is to use inputBindBlob() or inputBindClob() rather > than inputBind() to store the pickled data. inputBindBlob() and > inputBindClob() take a length parameter and ignore \0's. > > Give it a try and let me know whether it works or not. > > Dave > dav...@fi... > > On Thu, 2005-07-21 at 12:31 +0100, Ville Silventoinen wrote: >> Hi, >> >> I'm using PySQLRClient from sqlrelay-0.36 (with rudiments-0.28.2) >> to store blobs in Oracle 9.2.0 database. >> >> I'm not sure if this has been fixed in the recent sqlrelay release, >> but I'm experiencing problems when I store a Python data structure >> (dictionary object) to a blob using Pythons cPickle module. Everything >> works great until one of the values in the pickled object is an empty >> string (''). After that cPickle.load fails to read the data, it raises >> EOFError exception. So I wonder if PySQLRClient interprets the pickled >> '' as an end-of-file character? >> >> If I try loading/saving similar data structure to a file, it works ok. >> >> Thanks for any advice, >> >> Ville >> >> >> >> >> ------------------------------------------------------- >> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >> from IBM. Find simple to follow Roadmaps, straightforward articles, >> informative Webcasts and more! Get everything you need to get up to >> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click >> _______________________________________________ >> Sqlrelay-discussion mailing list >> Sql...@li... >> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion >> > > > > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > from IBM. Find simple to follow Roadmaps, straightforward articles, > informative Webcasts and more! Get everything you need to get up to > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > _______________________________________________ > Sqlrelay-discussion mailing list > Sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > |
From: linuxman <lin...@bl...> - 2005-07-21 14:09:21
|
hi all, I use mysql+php+adodb in my web application, and want to use sqlrelay as database polling. But, I don't know how to get insert id just after inserting a record with sqlrelay? you know , there is Insert_ID in adodb to get the insert id, but I have not find the same function in the php api of sqlrelay. I used the 0.36 version of sqlrelay. Any hints? Thanks in advance! Linuxman |
From: Josh J. <jos...@un...> - 2005-07-21 14:14:29
|
try: SELECT LAST_INSERT_ID(); -- JJ linuxman wrote: > >hi all, > >I use mysql+php+adodb in my web application, and want to use sqlrelay as >database polling. But, I don't know how to get insert id just after >inserting a record with sqlrelay? you know , there is Insert_ID in adodb to >get the insert id, but I have not find the same function in the php api of >sqlrelay. > >I used the 0.36 version of sqlrelay. > >Any hints? Thanks in advance! > >Linuxman > > > > > >------------------------------------------------------- >SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >from IBM. Find simple to follow Roadmaps, straightforward articles, >informative Webcasts and more! Get everything you need to get up to >speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click >_______________________________________________ >Sqlrelay-discussion mailing list >Sql...@li... >https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > |
From: linuxman <lin...@bl...> - 2005-07-21 14:51:46
|
thanks for JJ's quick response ! The code below is from the model class of my application: .... if the $query is insert something: $this->_masterDb =3D & Db::getDb("sqlrelay",9001); $this->_cur =3D sqlrcur_alloc( $this->_masterDb ); sqlrcur_sendQuery( $this->_cur, "set names 'utf8'" ); sqlrcur_sendQuery( $this->_cur, $query ); $result =3D $this->convertFromEmptySqlRelayResult($this->_cur); sqlrcur_sendQuery($this->_cur, "SELECT LAST_INSERT_ID() = as Insert_ID"); $row =3D sqlrcur_getRowAssoc($this->_cur); $this->log->debug("Row is = ".LogUtil::format($row)); $result->setInsertID($row["Insert_ID"]); sqlrcon_endSession($this->_masterDb); =20 and convertFromEmptySqlRelayResult is here: function convertFromEmptySqlRelayResult( $cur ){ $recordset =3D new EmptyMysqlResultSet_SqlRelay( $cur ); return $recordset; } And, EmptyMysqlResultSet_SqlRelay is defined as below: class EmptyMysqlResultSet_SqlRelay{ var $fields =3D false; var $EOF =3D true; function MoveNext() {return;} function RecordCount() {return 0;} function FieldCount() {return 0;} function EOF(){return TRUE;} function Close(){return true;} function emptyMysqlResultSet_SqlRelay($cur){ $this->cursor =3D $cur; } function Affected_Rows(){ return sqlrcur_affectedRows($this->cursor); } function setInsertID($id){ $this->insert_ID =3D $id; } function getInsertID(){ return $this->insert_ID; } } You see, sqlrelay is running port 9001, the query is like "INSERT ....". But the problem is, SELECT LAST_INSERT_ID() always return 0, I know = this by watch the log output of "$this->log->debug("Row is ".LogUtil::format($row))". Any problem of my codes ? or any other way to get insert id?=20 Thanks! -----=D3=CA=BC=FE=D4=AD=BC=FE----- =B7=A2=BC=FE=C8=CB: sql...@li... [mailto:sql...@li...] =B4=FA=B1=ED = Josh Johnson =B7=A2=CB=CD=CA=B1=BC=E4: 2005=C4=EA7=D4=C221=C8=D5 22:14 =CA=D5=BC=FE=C8=CB: sql...@li... =D6=F7=CC=E2: Re: [Sqlrelay-discussion] about insert_id try: SELECT LAST_INSERT_ID(); -- JJ linuxman wrote: >=20 >hi all, > >I use mysql+php+adodb in my web application, and want to use sqlrelay=20 >as database polling. But, I don't know how to get insert id just after=20 >inserting a record with sqlrelay? you know , there is Insert_ID in=20 >adodb to get the insert id, but I have not find the same function in=20 >the php api of sqlrelay. > >I used the 0.36 version of sqlrelay. > >Any hints? Thanks in advance! > >Linuxman > > > > > >------------------------------------------------------- >SF.Net email is sponsored by: Discover Easy Linux Migration Strategies=20 >from IBM. Find simple to follow Roadmaps, straightforward articles,=20 >informative Webcasts and more! Get everything you need to get up to=20 >speed, fast. = http://ads.osdn.com/?ad_id=3D7477&alloc_id=3D16492&op=3Dclick >_______________________________________________ >Sqlrelay-discussion mailing list >Sql...@li... >https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > =20 > ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies = from IBM. Find simple to follow Roadmaps, straightforward articles, = informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=3D7477&alloc_id=3D16492&op=3Dclick _______________________________________________ Sqlrelay-discussion mailing list Sql...@li... https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion |
From: Josh J. <jos...@un...> - 2005-07-21 15:09:25
|
I had a feeling it was more complicated than I thought :) I haven't used sqlrelay enough (I've been using it with PEAR) to have run into this problem myself, but it's something I'll have to deal with too... -- JJ linuxman wrote: >thanks for JJ's quick response ! > >The code below is from the model class of my application: > >.... >if the $query is insert something: > > $this->_masterDb =3D & Db::getDb("sqlrelay",9001); > $this->_cur =3D sqlrcur_alloc( $this->_masterDb ); > sqlrcur_sendQuery( $this->_cur, "set names 'utf8'" ); > sqlrcur_sendQuery( $this->_cur, $query ); > > $result =3D >$this->convertFromEmptySqlRelayResult($this->_cur); > > sqlrcur_sendQuery($this->_cur, "SELECT LAST_INSERT_ID() = as >Insert_ID"); > $row =3D sqlrcur_getRowAssoc($this->_cur); > $this->log->debug("Row is ".LogUtil::format($row= )); > $result->setInsertID($row["Insert_ID"]); > sqlrcon_endSession($this->_masterDb); >=20 >and convertFromEmptySqlRelayResult is here: > > function convertFromEmptySqlRelayResult( $cur ){ > $recordset =3D new EmptyMysqlResultSet_SqlRelay( $cur ); > return $recordset; > } > >And, EmptyMysqlResultSet_SqlRelay is defined as below: > >class EmptyMysqlResultSet_SqlRelay{ > var $fields =3D false; > var $EOF =3D true; > function MoveNext() {return;} > function RecordCount() {return 0;} > function FieldCount() {return 0;} > function EOF(){return TRUE;} > function Close(){return true;} > > function emptyMysqlResultSet_SqlRelay($cur){ > $this->cursor =3D $cur; > } > > function Affected_Rows(){ > return sqlrcur_affectedRows($this->cursor); > } > > function setInsertID($id){ > $this->insert_ID =3D $id; > } > > function getInsertID(){ > return $this->insert_ID; > } >} > >You see, sqlrelay is running port 9001, the query is like "INSERT ....". > >But the problem is, SELECT LAST_INSERT_ID() always return 0, I know thi= s by >watch the log output of "$this->log->debug("Row is >".LogUtil::format($row))". > >Any problem of my codes ? or any other way to get insert id?=20 > >Thanks! > >-----=D3=CA=BC=FE=D4=AD=BC=FE----- >=B7=A2=BC=FE=C8=CB: sql...@li... >[mailto:sql...@li...] =B4=FA=B1=ED Jo= sh Johnson >=B7=A2=CB=CD=CA=B1=BC=E4: 2005=C4=EA7=D4=C221=C8=D5 22:14 >=CA=D5=BC=FE=C8=CB: sql...@li... >=D6=F7=CC=E2: Re: [Sqlrelay-discussion] about insert_id > >try: SELECT LAST_INSERT_ID(); > >-- JJ > >linuxman wrote: > > =20 > >>hi all, >> >>I use mysql+php+adodb in my web application, and want to use sqlrelay=20 >>as database polling. But, I don't know how to get insert id just after=20 >>inserting a record with sqlrelay? you know , there is Insert_ID in=20 >>adodb to get the insert id, but I have not find the same function in=20 >>the php api of sqlrelay. >> >>I used the 0.36 version of sqlrelay. >> >>Any hints? Thanks in advance! >> >>Linuxman >> >> >> >> >> >>------------------------------------------------------- >>SF.Net email is sponsored by: Discover Easy Linux Migration Strategies=20 >> =20 >> >>from IBM. Find simple to follow Roadmaps, straightforward articles,=20 > =20 > >>informative Webcasts and more! Get everything you need to get up to=20 >>speed, fast. http://ads.osdn.com/?ad_id=3D7477&alloc_id=3D16492&op=3Dcl= ick >>_______________________________________________ >>Sqlrelay-discussion mailing list >>Sql...@li... >>https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion >>=20 >> >> =20 >> > > > > >------------------------------------------------------- >SF.Net email is sponsored by: Discover Easy Linux Migration Strategies f= rom >IBM. Find simple to follow Roadmaps, straightforward articles, informati= ve >Webcasts and more! Get everything you need to get up to speed, fast. >http://ads.osdn.com/?ad_id=3D7477&alloc_id=3D16492&op=3Dclick >_______________________________________________ >Sqlrelay-discussion mailing list >Sql...@li... >https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > > > >------------------------------------------------------- >SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >from IBM. Find simple to follow Roadmaps, straightforward articles, >informative Webcasts and more! Get everything you need to get up to >speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id=16492&op=3Dclick >_______________________________________________ >Sqlrelay-discussion mailing list >Sql...@li... >https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > =20 > |
From: linuxman <lin...@bl...> - 2005-07-22 01:32:12
|
Work it out! =20 It seemed that, this line: =20 $row =3D sqlrcur_getRowAssoc($this->_cur); =20 has something wrong, I replace this line with: =20 $insertId =3D sqlcrur_getField($this->_cur, 0, "Insert_ID"); =20 then everything go well... =20 But another problem, I don't know when to free the resources that sqlrcon_alloc and sqlrcur_alloc applied? =20 The trick is that, I can not free the cursor returned by = sqlcur_sendQuery just after sendQuery finished, because I must transfer the cursor to resultset as the parameter.=20 =20 Thanks!=20 _____ =20 =B7=A2=BC=FE=C8=CB: sql...@li... [mailto:sql...@li...] =B4=FA=B1=ED = Josh Johnson =B7=A2=CB=CD=CA=B1=BC=E4: 2005=C4=EA7=D4=C221=C8=D5 23:08 =CA=D5=BC=FE=C8=CB: sql...@li... =D6=F7=CC=E2: Re: [Sqlrelay-discussion] =B4=F0=B8=B4: = [Sqlrelay-discussion] about insert_id I had a feeling it was more complicated than I thought :) I haven't used sqlrelay enough (I've been using it with PEAR) to have run into this = problem myself, but it's something I'll have to deal with too...=20 -- JJ linuxman wrote:=20 thanks for JJ's quick response ! The code below is from the model class of my application: .... if the $query is insert something: $this->_masterDb =3D & Db::getDb("sqlrelay",9001); $this->_cur =3D sqlrcur_alloc( $this->_masterDb ); sqlrcur_sendQuery( $this->_cur, "set names 'utf8'" ); sqlrcur_sendQuery( $this->_cur, $query ); $result =3D $this->convertFromEmptySqlRelayResult($this->_cur); sqlrcur_sendQuery($this->_cur, "SELECT LAST_INSERT_ID() = as Insert_ID"); $row =3D sqlrcur_getRowAssoc($this->_cur); $this->log->debug("Row is = ".LogUtil::format($row)); $result->setInsertID($row["Insert_ID"]); sqlrcon_endSession($this->_masterDb); =20 and convertFromEmptySqlRelayResult is here: function convertFromEmptySqlRelayResult( $cur ){ $recordset =3D new EmptyMysqlResultSet_SqlRelay( $cur ); return $recordset; } And, EmptyMysqlResultSet_SqlRelay is defined as below: class EmptyMysqlResultSet_SqlRelay{ var $fields =3D false; var $EOF =3D true; function MoveNext() {return;} function RecordCount() {return 0;} function FieldCount() {return 0;} function EOF(){return TRUE;} function Close(){return true;} function emptyMysqlResultSet_SqlRelay($cur){ $this->cursor =3D $cur; } function Affected_Rows(){ return sqlrcur_affectedRows($this->cursor); } function setInsertID($id){ $this->insert_ID =3D $id; } function getInsertID(){ return $this->insert_ID; } } You see, sqlrelay is running port 9001, the query is like "INSERT ....". But the problem is, SELECT LAST_INSERT_ID() always return 0, I know = this by watch the log output of "$this->log->debug("Row is ".LogUtil::format($row))". Any problem of my codes ? or any other way to get insert id?=20 Thanks! -----=D3=CA=BC=FE=D4=AD=BC=FE----- =B7=A2=BC=FE=C8=CB: sql...@li... [mailto:sql...@li...] =B4=FA=B1=ED = Josh Johnson =B7=A2=CB=CD=CA=B1=BC=E4: 2005=C4=EA7=D4=C221=C8=D5 22:14 =CA=D5=BC=FE=C8=CB: sql...@li... =D6=F7=CC=E2: Re: [Sqlrelay-discussion] about insert_id try: SELECT LAST_INSERT_ID(); -- JJ linuxman wrote: =20 hi all, I use mysql+php+adodb in my web application, and want to use sqlrelay=20 as database polling. But, I don't know how to get insert id just after=20 inserting a record with sqlrelay? you know , there is Insert_ID in=20 adodb to get the insert id, but I have not find the same function in=20 the php api of sqlrelay. I used the 0.36 version of sqlrelay. Any hints? Thanks in advance! Linuxman ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies=20 =20 >from IBM. Find simple to follow Roadmaps, straightforward articles,=20 =20 informative Webcasts and more! Get everything you need to get up to=20 speed, fast. http://ads.osdn.com/?ad_id=3D7477 <http://ads.osdn.com/?ad_id=3D7477&alloc_id=3D16492&op=3Dclick> &alloc_id=3D16492&op=3Dclick _______________________________________________ Sqlrelay-discussion mailing list Sql...@li... https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion =20 =20 ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies = from IBM. Find simple to follow Roadmaps, straightforward articles, = informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=3D7477 <http://ads.osdn.com/?ad_id=3D7477&alloc_id=3D16492&op=3Dclick> &alloc_id=3D16492&op=3Dclick _______________________________________________ Sqlrelay-discussion mailing list Sql...@li... https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion ------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77 <http://ads.osdn.com/?ad_idt77&alloc_id=16492&op=3Dclick> = &alloc_id=16492&op=3Dclick _______________________________________________ Sqlrelay-discussion mailing list Sql...@li... https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion =20 |
From: linuxman <lin...@bl...> - 2005-07-22 09:42:23
|
hi all, Here is pstree output in my debian/linux box: sqlr-cachemanag 10*[sqlr-connection] 2*[sqlr-listener] 2*[sqlr-scaler] and, only one mysqld daemon there! very strange here. The problem is, is it normal or something wrong with my sqlrelay configuration? Here is my sqlrelay.conf: <?xml version="1.0"?> <!DOCTYPE instances SYSTEM "sqlrelay.dtd"> <instances> <instance id="test1" port="9000" socket="/usr/local/firstworks/var/sqlrelay/tmp/sqlrelay_9000.sock" dbase="mysql" connections="5" maxconnections="75" maxqueuelength="5" growby="5" ttl="60" endofsession="commit" sessiontimeout="600" runasuser="sqlrelay" runasgroup="sqlrelay" cursors="5" authtier="listener" handoff="pass" deniedips="" allowedips="" debug="connection"> <users> <user user="root" password="xxx"/ <mailto:mysql@peakinfo> > </users> <connections> <connection connectionid="test" string="user=root;password=xxx;db=xxx;socket=/var/run/mysqld/mysqld.sock" /> </connections> </instance> <instance id="test2" port="9001" socket="/usr/local/firstworks/var/sqlrelay/tmp/sqlrelay_9001.sock" dbase="mysql" connections="5" maxconnections="75" maxqueuelength="5" growby="1" ttl="60" endofsession="commit" sessiontimeout="600" runasuser="sqlrelay" runasgroup="sqlrelay" cursors="5" authtier="listener" handoff="pass" deniedips="" allowedips="" debug="connection"> <users> <user user="root" password="xxx"/ <mailto:mysql@peakinfo> > </users> <connections> <connection connectionid="test3" string="user=root;password=xxx;db=test;host=localhost;port=3306" /> </connections> </instance> </instances> Thanks in advance! linuxman |
From: David M. <dav...@fi...> - 2005-07-27 01:36:52
|
Hmm. That is interesting. I get the same result when I try it and it works when I run a bunch of client programs. I guess mysql multiplexes client connections through a single process these days. David Muse dav...@fi... On Fri, 2005-07-22 at 17:15 +0800, linuxman wrote: > hi all, > > Here is pstree output in my debian/linux box: > sqlr-cachemanag > 10*[sqlr-connection] > 2*[sqlr-listener] > 2*[sqlr-scaler] > > and, only one mysqld daemon there! very strange here. > > The problem is, is it normal or something wrong with my sqlrelay > configuration? > > Here is my sqlrelay.conf: > > <?xml version="1.0"?> > <!DOCTYPE instances SYSTEM "sqlrelay.dtd"> > > <instances> > > <instance id="test1" port="9000" > socket="/usr/local/firstworks/var/sqlrelay/tmp/sqlrelay_9000.sock" > dbase="mysql" connections="5" maxconnections="75" > maxqueuelength="5" growby="5" ttl="60" endofsession="commit" > sessiontimeout="600" runasuser="sqlrelay" > runasgroup="sqlrelay" cursors="5" authtier="listener" handoff="pass" > deniedips="" allowedips="" debug="connection"> > <users> > <user user="root" password="xxx"/> > </users> > <connections> > <connection connectionid="test" > string="user=root;password=xxx;db=xxx;socket=/var/run/mysqld/mysqld.sock" /> > </connections> > </instance> > > <instance id="test2" port="9001" > socket="/usr/local/firstworks/var/sqlrelay/tmp/sqlrelay_9001.sock" > dbase="mysql" connections="5" maxconnections="75" > maxqueuelength="5" growby="1" ttl="60" endofsession="commit" > sessiontimeout="600" runasuser="sqlrelay" runasgroup="sqlrelay" > cursors="5" authtier="listener" handoff="pass" deniedips="" > allowedips="" debug="connection"> > <users> > <user user="root" password="xxx"/> > </users> > <connections> > <connection connectionid="test3" > string="user=root;password=xxx;db=test;host=localhost;port=3306" /> > </connections> > </instance> > </instances> > > Thanks in advance! > > linuxman |
From: David M. <dav...@fi...> - 2005-07-27 01:55:51
|
I believe you need to use 2 cursors in your code. $this->_masterDb = & Db::getDb("sqlrelay",9001); $this->_cur = sqlrcur_alloc( $this->_masterDb ); sqlrcur_sendQuery( $this->_cur, "set names 'utf8'" ); sqlrcur_sendQuery( $this->_cur, $query ); $result = $this->convertFromEmptySqlRelayResult($this->_cur); $this->_cur2 = sqlrcur_alloc( $this->_masterDb ); sqlrcur_sendQuery($this->_cur2, "SELECT LAST_INSERT_ID() as Insert_ID"); $row = sqlrcur_getRowAssoc($this->_cur2, 0); $this->log->debug("Row is ".LogUtil::format($row)); $result->setInsertID($row["Insert_ID"]); sqlrcur_free($this->_cur); sqlrcur_free($this->_cur2); sqlrcon_endSession($this->_masterDb); Each cursor can only keep track of a single result set. If you run 1 query (in this case $query) and then use the same cursor to run another query (in this case "select LAST_INSERT_ID() as Insert_ID") then the result set of $query will be lost. In this short bit of code, it doesn't matter, but if it had called $result->Affected_Rows() after running "select LAST_INSERT_ID()..." then it $result->Affected_Rows() would return the number of affected rows from "select LAST_INSERT_ID()..." because the cursor that was attached to $result was reused for that query. I added sqlrcur_free calls above where it's safe to delete the cursors. Also, sqlrcur_getRowAssoc() requires 2 parameters: the cursor and the row number. In this case, row 0. I added the second parameter in the code above too. Give it a try and let me know how it goes. David Muse dav...@fi... On Fri, 2005-07-22 at 09:25 +0800, linuxman wrote: > Work it out! > > It seemed that, this line: > > $row = sqlrcur_getRowAssoc($this->_cur); > > has something wrong, I replace this line with: > > $insertId = sqlcrur_getField($this->_cur, 0, "Insert_ID"); > > then everything go well... > > But another problem, I don't know when to free the resources that > sqlrcon_alloc and sqlrcur_alloc applied? > > The trick is that, I can not free the cursor returned by > sqlcur_sendQuery just after sendQuery finished, because I must > transfer the cursor to resultset as the parameter. > > Thanks! > > > > > ______________________________________________________________________ > 发件人: sql...@li... > [mailto:sql...@li...] 代表 Josh > Johnson > 发送时间: 2005年7月21日 23:08 > 收件人: sql...@li... > 主题: Re: [Sqlrelay-discussion] 答复: [Sqlrelay-discussion] about > insert_id > > > > I had a feeling it was more complicated than I thought :) I haven't > used sqlrelay enough (I've been using it with PEAR) to have run into > this problem myself, but it's something I'll have to deal with too... > > -- JJ > > linuxman wrote: > > thanks for JJ's quick response ! > > > > The code below is from the model class of my application: > > > > .... > > if the $query is insert something: > > > > $this->_masterDb = & Db::getDb("sqlrelay",9001); > > $this->_cur = sqlrcur_alloc( $this->_masterDb ); > > sqlrcur_sendQuery( $this->_cur, "set names 'utf8'" ); > > sqlrcur_sendQuery( $this->_cur, $query ); > > > > $result = > > $this->convertFromEmptySqlRelayResult($this->_cur); > > > > sqlrcur_sendQuery($this->_cur, "SELECT LAST_INSERT_ID() as > > Insert_ID"); > > $row = sqlrcur_getRowAssoc($this->_cur); > > $this->log->debug("Row is ".LogUtil::format($row)); > > $result->setInsertID($row["Insert_ID"]); > > sqlrcon_endSession($this->_masterDb); > > > > and convertFromEmptySqlRelayResult is here: > > > > function convertFromEmptySqlRelayResult( $cur ){ > > $recordset = new EmptyMysqlResultSet_SqlRelay( $cur ); > > return $recordset; > > } > > > > And, EmptyMysqlResultSet_SqlRelay is defined as below: > > > > class EmptyMysqlResultSet_SqlRelay{ > > var $fields = false; > > var $EOF = true; > > function MoveNext() {return;} > > function RecordCount() {return 0;} > > function FieldCount() {return 0;} > > function EOF(){return TRUE;} > > function Close(){return true;} > > > > function emptyMysqlResultSet_SqlRelay($cur){ > > $this->cursor = $cur; > > } > > > > function Affected_Rows(){ > > return sqlrcur_affectedRows($this->cursor); > > } > > > > function setInsertID($id){ > > $this->insert_ID = $id; > > } > > > > function getInsertID(){ > > return $this->insert_ID; > > } > > } > > > > You see, sqlrelay is running port 9001, the query is like "INSERT ....". > > > > But the problem is, SELECT LAST_INSERT_ID() always return 0, I know this by > > watch the log output of "$this->log->debug("Row is > > ".LogUtil::format($row))". > > > > Any problem of my codes ? or any other way to get insert id? > > > > Thanks! > > > > -----邮件原件----- > > 发件人: sql...@li... > > [mailto:sql...@li...] 代表 Josh Johnson > > 发送时间: 2005年7月21日 22:14 > > 收件人: sql...@li... > > 主题: Re: [Sqlrelay-discussion] about insert_id > > > > try: SELECT LAST_INSERT_ID(); > > > > -- JJ > > > > linuxman wrote: > > > > > > > hi all, > > > > > > I use mysql+php+adodb in my web application, and want to use sqlrelay > > > as database polling. But, I don't know how to get insert id just after > > > inserting a record with sqlrelay? you know , there is Insert_ID in > > > adodb to get the insert id, but I have not find the same function in > > > the php api of sqlrelay. > > > > > > I used the 0.36 version of sqlrelay. > > > > > > Any hints? Thanks in advance! > > > > > > Linuxman > > > > > > > > > > > > > > > > > > ------------------------------------------------------- > > > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > > > > > >from IBM. Find simple to follow Roadmaps, straightforward articles, > > > > > informative Webcasts and more! Get everything you need to get up to > > > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > > > _______________________________________________ > > > Sqlrelay-discussion mailing list > > > Sql...@li... > > > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > > > > > > > > > > > > > > > > > > ------------------------------------------------------- > > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from > > IBM. Find simple to follow Roadmaps, straightforward articles, informative > > Webcasts and more! Get everything you need to get up to speed, fast. > > http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > > _______________________________________________ > > Sqlrelay-discussion mailing list > > Sql...@li... > > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > > > > > > > > > ------------------------------------------------------- > > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > > from IBM. Find simple to follow Roadmaps, straightforward articles, > > informative Webcasts and more! Get everything you need to get up to > > speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click > > _______________________________________________ > > Sqlrelay-discussion mailing list > > Sql...@li... > > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > > |
From: Ville S. <vs...@eb...> - 2005-07-21 15:11:06
|
Hi Dave, Python len seems to be working correctly with pickled data. I did find out that cPickle.dumps(sdata) works ok. This generates string representation of the pickled data, which doesn't contain a \0 character. (I had a typo in my earlier test, the create procedure used string data, the modify procedure used binary, which is why I thought neither dumps worked.) If I use the HIGHEST_PROTOCOL with dumps, it generates binary data. This seems to have a problem with inputBindBlob(), unless I'm still doing something wrong. So if I am right, you should be able to recreate the problem with something like this: sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', 3:'bar'}}} ... bdata = cPickle.dumps(sdata, 2) # uses HIGHEST_PROTOCOL blen = len(bdata) cur.inputBindBlob('colname', bdata, blen) ... # read the data by using normal select ... mydata = cPickle.loads(fields[0]) # this throws EOFError (at least in my case) I think '' generates \x00 or \x0, which becomes EOF with inputBindBlob. Perhaps it encodes \x00 as \0? Or maybe the problem is in the select? Is it ok to use normal select to read blobs? Thanks, Ville On Thu, 21 Jul 2005, Firstworks/4access wrote: > Ville, > > I was actually looking at that last night. I'm believe you're on track. > inputBind() does a strlen() of the string to decide how many characters > to store in the database. strlen() interprets \0's as end-of-string > markers, so only part of the data gets stored in the blob. Then, later > when you fetch and unpickle it, only part of it gets unpickled. I > believe the solution is to use inputBindBlob() or inputBindClob() rather > than inputBind() to store the pickled data. inputBindBlob() and > inputBindClob() take a length parameter and ignore \0's. > > Give it a try and let me know whether it works or not. > > Dave > dav...@fi... > > On Thu, 2005-07-21 at 12:31 +0100, Ville Silventoinen wrote: >> Hi, >> >> I'm using PySQLRClient from sqlrelay-0.36 (with rudiments-0.28.2) >> to store blobs in Oracle 9.2.0 database. >> >> I'm not sure if this has been fixed in the recent sqlrelay release, >> but I'm experiencing problems when I store a Python data structure >> (dictionary object) to a blob using Pythons cPickle module. Everything >> works great until one of the values in the pickled object is an empty >> string (''). After that cPickle.load fails to read the data, it raises >> EOFError exception. So I wonder if PySQLRClient interprets the pickled >> '' as an end-of-file character? >> >> If I try loading/saving similar data structure to a file, it works ok. >> >> Thanks for any advice, >> >> Ville >> >> >> >> >> ------------------------------------------------------- >> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >> from IBM. Find simple to follow Roadmaps, straightforward articles, >> informative Webcasts and more! Get everything you need to get up to >> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click >> _______________________________________________ >> Sqlrelay-discussion mailing list >> Sql...@li... >> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion >> > > > > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > from IBM. Find simple to follow Roadmaps, straightforward articles, > informative Webcasts and more! Get everything you need to get up to > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > _______________________________________________ > Sqlrelay-discussion mailing list > Sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > |
From: David M. <dav...@fi...> - 2005-07-27 01:59:03
|
It should be ok to use select to fetch a blob. But, since the blob may contain NULLs, you need to use both getField() and getFieldLength() to deal with it. I wonder what cPickle.loads() does to decide how long the array of binary data is. Maybe it stores it in the beginning of the array or something. I'll run some tests and see what I get. Dave dav...@fi... On Thu, 2005-07-21 at 16:10 +0100, Ville Silventoinen wrote: > Hi Dave, > > Python len seems to be working correctly with pickled data. > > I did find out that cPickle.dumps(sdata) works ok. This generates string > representation of the pickled data, which doesn't contain a \0 character. > (I had a typo in my earlier test, the create procedure used string data, > the modify procedure used binary, which is why I thought neither dumps > worked.) > > If I use the HIGHEST_PROTOCOL with dumps, it generates binary data. This > seems to have a problem with inputBindBlob(), unless I'm still doing > something wrong. So if I am right, you should be able to recreate the > problem with something like this: > > sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', 3:'bar'}}} > ... > bdata = cPickle.dumps(sdata, 2) # uses HIGHEST_PROTOCOL > blen = len(bdata) > cur.inputBindBlob('colname', bdata, blen) > ... > # read the data by using normal select > ... > mydata = cPickle.loads(fields[0]) > # this throws EOFError (at least in my case) > > I think '' generates \x00 or \x0, which becomes EOF with inputBindBlob. > Perhaps it encodes \x00 as \0? Or maybe the problem is in the select? > Is it ok to use normal select to read blobs? > > Thanks, > Ville > > > On Thu, 21 Jul 2005, Firstworks/4access wrote: > > > Ville, > > > > I was actually looking at that last night. I'm believe you're on track. > > inputBind() does a strlen() of the string to decide how many characters > > to store in the database. strlen() interprets \0's as end-of-string > > markers, so only part of the data gets stored in the blob. Then, later > > when you fetch and unpickle it, only part of it gets unpickled. I > > believe the solution is to use inputBindBlob() or inputBindClob() rather > > than inputBind() to store the pickled data. inputBindBlob() and > > inputBindClob() take a length parameter and ignore \0's. > > > > Give it a try and let me know whether it works or not. > > > > Dave > > dav...@fi... > > > > On Thu, 2005-07-21 at 12:31 +0100, Ville Silventoinen wrote: > >> Hi, > >> > >> I'm using PySQLRClient from sqlrelay-0.36 (with rudiments-0.28.2) > >> to store blobs in Oracle 9.2.0 database. > >> > >> I'm not sure if this has been fixed in the recent sqlrelay release, > >> but I'm experiencing problems when I store a Python data structure > >> (dictionary object) to a blob using Pythons cPickle module. Everything > >> works great until one of the values in the pickled object is an empty > >> string (''). After that cPickle.load fails to read the data, it raises > >> EOFError exception. So I wonder if PySQLRClient interprets the pickled > >> '' as an end-of-file character? > >> > >> If I try loading/saving similar data structure to a file, it works ok. > >> > >> Thanks for any advice, > >> > >> Ville > >> > >> > >> > >> > >> ------------------------------------------------------- > >> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > >> from IBM. Find simple to follow Roadmaps, straightforward articles, > >> informative Webcasts and more! Get everything you need to get up to > >> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > >> _______________________________________________ > >> Sqlrelay-discussion mailing list > >> Sql...@li... > >> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > >> > > > > > > > > ------------------------------------------------------- > > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > > from IBM. Find simple to follow Roadmaps, straightforward articles, > > informative Webcasts and more! Get everything you need to get up to > > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > > _______________________________________________ > > Sqlrelay-discussion mailing list > > Sql...@li... > > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > > > > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > from IBM. Find simple to follow Roadmaps, straightforward articles, > informative Webcasts and more! Get everything you need to get up to > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > _______________________________________________ > Sqlrelay-discussion mailing list > Sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > |
From: David M. <dav...@fi...> - 2005-07-28 02:08:54
|
Ville, I have run some tests with my development version and the following script works: #! /usr/bin/env python # Copyright (c) 2001 David Muse # See the file COPYING for more information. from SQLRelay import PySQLRClient import sys import string import cPickle con=PySQLRClient.sqlrconnection("localhost",8009,"/tmp/oracle8test.socket","oracle8test","oracle8test") #con.debugOn() cur=PySQLRClient.sqlrcursor(con) cur.sendQuery("drop table testtable"); cur.sendQuery("create table testtable (col1 blob)") cur.prepareQuery("insert into testtable values(:val1)"); sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', 3:'bar'}}} bdata=cPickle.dumps(sdata) blen=len(bdata) cur.inputBindBlob('val1',bdata,blen) cur.executeQuery() cur.sendQuery("select * from testtable"); mydata=cPickle.loads(cur.getField(0,0)) print mydata cur.sendQuery("select * from testtable"); fields=cur.getRow(0) mydata=cPickle.loads(fields[0]) print mydata cur.sendQuery("drop table testtable"); It prints out a tuple identical to the one sdata is set to. See if it doesn't work for you too. If not, then there may be a bug specific to the version of SQL Relay you're using. What version is that, by the way? Dave On Thu, 2005-07-21 at 16:10 +0100, Ville Silventoinen wrote: > Hi Dave, > > Python len seems to be working correctly with pickled data. > > I did find out that cPickle.dumps(sdata) works ok. This generates string > representation of the pickled data, which doesn't contain a \0 character. > (I had a typo in my earlier test, the create procedure used string data, > the modify procedure used binary, which is why I thought neither dumps > worked.) > > If I use the HIGHEST_PROTOCOL with dumps, it generates binary data. This > seems to have a problem with inputBindBlob(), unless I'm still doing > something wrong. So if I am right, you should be able to recreate the > problem with something like this: > > sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', 3:'bar'}}} > ... > bdata = cPickle.dumps(sdata, 2) # uses HIGHEST_PROTOCOL > blen = len(bdata) > cur.inputBindBlob('colname', bdata, blen) > ... > # read the data by using normal select > ... > mydata = cPickle.loads(fields[0]) > # this throws EOFError (at least in my case) > > I think '' generates \x00 or \x0, which becomes EOF with inputBindBlob. > Perhaps it encodes \x00 as \0? Or maybe the problem is in the select? > Is it ok to use normal select to read blobs? > > Thanks, > Ville > > > On Thu, 21 Jul 2005, Firstworks/4access wrote: > > > Ville, > > > > I was actually looking at that last night. I'm believe you're on track. > > inputBind() does a strlen() of the string to decide how many characters > > to store in the database. strlen() interprets \0's as end-of-string > > markers, so only part of the data gets stored in the blob. Then, later > > when you fetch and unpickle it, only part of it gets unpickled. I > > believe the solution is to use inputBindBlob() or inputBindClob() rather > > than inputBind() to store the pickled data. inputBindBlob() and > > inputBindClob() take a length parameter and ignore \0's. > > > > Give it a try and let me know whether it works or not. > > > > Dave > > dav...@fi... > > > > On Thu, 2005-07-21 at 12:31 +0100, Ville Silventoinen wrote: > >> Hi, > >> > >> I'm using PySQLRClient from sqlrelay-0.36 (with rudiments-0.28.2) > >> to store blobs in Oracle 9.2.0 database. > >> > >> I'm not sure if this has been fixed in the recent sqlrelay release, > >> but I'm experiencing problems when I store a Python data structure > >> (dictionary object) to a blob using Pythons cPickle module. Everything > >> works great until one of the values in the pickled object is an empty > >> string (''). After that cPickle.load fails to read the data, it raises > >> EOFError exception. So I wonder if PySQLRClient interprets the pickled > >> '' as an end-of-file character? > >> > >> If I try loading/saving similar data structure to a file, it works ok. > >> > >> Thanks for any advice, > >> > >> Ville > >> > >> > >> > >> > >> ------------------------------------------------------- > >> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > >> from IBM. Find simple to follow Roadmaps, straightforward articles, > >> informative Webcasts and more! Get everything you need to get up to > >> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > >> _______________________________________________ > >> Sqlrelay-discussion mailing list > >> Sql...@li... > >> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > >> > > > > > > > > ------------------------------------------------------- > > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > > from IBM. Find simple to follow Roadmaps, straightforward articles, > > informative Webcasts and more! Get everything you need to get up to > > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > > _______________________________________________ > > Sqlrelay-discussion mailing list > > Sql...@li... > > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > > > > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > from IBM. Find simple to follow Roadmaps, straightforward articles, > informative Webcasts and more! Get everything you need to get up to > speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > _______________________________________________ > Sqlrelay-discussion mailing list > Sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > |
From: Ville S. <vs...@eb...> - 2005-07-28 08:29:37
|
Hi Dave, thank you very much for putting your time into this. As I tried to explain in my earlier mail (I'm not very good in explaining things!), the problem happens when I use cPickle.dumps to generate a binary string, not a text string. You get a binary string by specifying a second parameter '2' (according to my source, Python Cookbook, 2nd ed): bdata=cPickle.dumps(sdata, 2) When I run your test script, it works, because cPickle.dumps(sdata) generates a text string. But when I do the above change, I get an error: {'spam': {'eggs': 'spamspam', 'answers': {1: '', 2: 'foo', 3: 'bar'}}} Traceback (most recent call last): File "./testsqlr.py", line 32, in ? mydata=cPickle.loads(fields[0]) EOFError It's not really necessary to use a binary string in my case, so I wouldn't give this problem a very high priority. The Python Cookbook states that using binary strings is "faster and takes up less space". I haven't had time to try your suggestion about using getField() and getFieldLength() for blobs. I'll try it in the next few days. My SQLRelay is version 0.36 with rudiments 0.28.2. Thanks again! Ville On Wed, 27 Jul 2005, David Muse wrote: > Ville, > > I have run some tests with my development version and the following > script works: > > #! /usr/bin/env python > > # Copyright (c) 2001 David Muse > # See the file COPYING for more information. > > from SQLRelay import PySQLRClient > import sys > import string > import cPickle > > con=PySQLRClient.sqlrconnection("localhost",8009,"/tmp/oracle8test.socket","oracle8test","oracle8test") > #con.debugOn() > cur=PySQLRClient.sqlrcursor(con) > > cur.sendQuery("drop table testtable"); > cur.sendQuery("create table testtable (col1 blob)") > > cur.prepareQuery("insert into testtable values(:val1)"); > sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', > 3:'bar'}}} > bdata=cPickle.dumps(sdata) > blen=len(bdata) > cur.inputBindBlob('val1',bdata,blen) > cur.executeQuery() > > cur.sendQuery("select * from testtable"); > mydata=cPickle.loads(cur.getField(0,0)) > print mydata > > cur.sendQuery("select * from testtable"); > fields=cur.getRow(0) > mydata=cPickle.loads(fields[0]) > print mydata > > cur.sendQuery("drop table testtable"); > > > It prints out a tuple identical to the one sdata is set to. See if it > doesn't work for you too. If not, then there may be a bug specific to > the version of SQL Relay you're using. What version is that, by the > way? > > Dave > > > On Thu, 2005-07-21 at 16:10 +0100, Ville Silventoinen wrote: >> Hi Dave, >> >> Python len seems to be working correctly with pickled data. >> >> I did find out that cPickle.dumps(sdata) works ok. This generates string >> representation of the pickled data, which doesn't contain a \0 character. >> (I had a typo in my earlier test, the create procedure used string data, >> the modify procedure used binary, which is why I thought neither dumps >> worked.) >> >> If I use the HIGHEST_PROTOCOL with dumps, it generates binary data. This >> seems to have a problem with inputBindBlob(), unless I'm still doing >> something wrong. So if I am right, you should be able to recreate the >> problem with something like this: >> >> sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', 3:'bar'}}} >> ... >> bdata = cPickle.dumps(sdata, 2) # uses HIGHEST_PROTOCOL >> blen = len(bdata) >> cur.inputBindBlob('colname', bdata, blen) >> ... >> # read the data by using normal select >> ... >> mydata = cPickle.loads(fields[0]) >> # this throws EOFError (at least in my case) >> >> I think '' generates \x00 or \x0, which becomes EOF with inputBindBlob. >> Perhaps it encodes \x00 as \0? Or maybe the problem is in the select? >> Is it ok to use normal select to read blobs? >> >> Thanks, >> Ville >> >> >> On Thu, 21 Jul 2005, Firstworks/4access wrote: >> >>> Ville, >>> >>> I was actually looking at that last night. I'm believe you're on track. >>> inputBind() does a strlen() of the string to decide how many characters >>> to store in the database. strlen() interprets \0's as end-of-string >>> markers, so only part of the data gets stored in the blob. Then, later >>> when you fetch and unpickle it, only part of it gets unpickled. I >>> believe the solution is to use inputBindBlob() or inputBindClob() rather >>> than inputBind() to store the pickled data. inputBindBlob() and >>> inputBindClob() take a length parameter and ignore \0's. >>> >>> Give it a try and let me know whether it works or not. >>> >>> Dave >>> dav...@fi... >>> >>> On Thu, 2005-07-21 at 12:31 +0100, Ville Silventoinen wrote: >>>> Hi, >>>> >>>> I'm using PySQLRClient from sqlrelay-0.36 (with rudiments-0.28.2) >>>> to store blobs in Oracle 9.2.0 database. >>>> >>>> I'm not sure if this has been fixed in the recent sqlrelay release, >>>> but I'm experiencing problems when I store a Python data structure >>>> (dictionary object) to a blob using Pythons cPickle module. Everything >>>> works great until one of the values in the pickled object is an empty >>>> string (''). After that cPickle.load fails to read the data, it raises >>>> EOFError exception. So I wonder if PySQLRClient interprets the pickled >>>> '' as an end-of-file character? >>>> >>>> If I try loading/saving similar data structure to a file, it works ok. >>>> >>>> Thanks for any advice, >>>> >>>> Ville >>>> >>>> >>>> >>>> >>>> ------------------------------------------------------- >>>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >>>> from IBM. Find simple to follow Roadmaps, straightforward articles, >>>> informative Webcasts and more! Get everything you need to get up to >>>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click >>>> _______________________________________________ >>>> Sqlrelay-discussion mailing list >>>> Sql...@li... >>>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion >>>> >>> >>> >>> >>> ------------------------------------------------------- >>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >>> from IBM. Find simple to follow Roadmaps, straightforward articles, >>> informative Webcasts and more! Get everything you need to get up to >>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click >>> _______________________________________________ >>> Sqlrelay-discussion mailing list >>> Sql...@li... >>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion >>> >> >> >> ------------------------------------------------------- >> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >> from IBM. Find simple to follow Roadmaps, straightforward articles, >> informative Webcasts and more! Get everything you need to get up to >> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click >> _______________________________________________ >> Sqlrelay-discussion mailing list >> Sql...@li... >> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion >> > > > > ------------------------------------------------------- > SF.Net email is Sponsored by the Better Software Conference & EXPO September > 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > _______________________________________________ > Sqlrelay-discussion mailing list > Sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > |
From: Firstworks/4access <dav...@fi...> - 2005-07-28 14:58:48
|
Sorry, I forgot to mention. I tried cPickle.dumps(sdata) and cPickle.dumps(sdata,2) and both worked for me. I wonder if there's a bug in 0.36 that's causing the error. I'll give it a try tonight and let you know what I find. Dave On Thu, 2005-07-28 at 09:28 +0100, Ville Silventoinen wrote: > Hi Dave, > > thank you very much for putting your time into this. As I tried to explain > in my earlier mail (I'm not very good in explaining things!), the problem > happens when I use cPickle.dumps to generate a binary string, not a text > string. You get a binary string by specifying a second parameter '2' > (according to my source, Python Cookbook, 2nd ed): > > bdata=cPickle.dumps(sdata, 2) > > When I run your test script, it works, because cPickle.dumps(sdata) > generates a text string. But when I do the above change, I get an error: > > {'spam': {'eggs': 'spamspam', 'answers': {1: '', 2: 'foo', 3: 'bar'}}} > Traceback (most recent call last): > File "./testsqlr.py", line 32, in ? > mydata=cPickle.loads(fields[0]) > EOFError > > It's not really necessary to use a binary string in my case, so I wouldn't > give this problem a very high priority. The Python Cookbook states that > using binary strings is "faster and takes up less space". > > I haven't had time to try your suggestion about using getField() and > getFieldLength() for blobs. I'll try it in the next few days. > > My SQLRelay is version 0.36 with rudiments 0.28.2. > > Thanks again! > > Ville > > > On Wed, 27 Jul 2005, David Muse wrote: > > > Ville, > > > > I have run some tests with my development version and the following > > script works: > > > > #! /usr/bin/env python > > > > # Copyright (c) 2001 David Muse > > # See the file COPYING for more information. > > > > from SQLRelay import PySQLRClient > > import sys > > import string > > import cPickle > > > > con=PySQLRClient.sqlrconnection("localhost",8009,"/tmp/oracle8test.socket","oracle8test","oracle8test") > > #con.debugOn() > > cur=PySQLRClient.sqlrcursor(con) > > > > cur.sendQuery("drop table testtable"); > > cur.sendQuery("create table testtable (col1 blob)") > > > > cur.prepareQuery("insert into testtable values(:val1)"); > > sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', > > 3:'bar'}}} > > bdata=cPickle.dumps(sdata) > > blen=len(bdata) > > cur.inputBindBlob('val1',bdata,blen) > > cur.executeQuery() > > > > cur.sendQuery("select * from testtable"); > > mydata=cPickle.loads(cur.getField(0,0)) > > print mydata > > > > cur.sendQuery("select * from testtable"); > > fields=cur.getRow(0) > > mydata=cPickle.loads(fields[0]) > > print mydata > > > > cur.sendQuery("drop table testtable"); > > > > > > It prints out a tuple identical to the one sdata is set to. See if it > > doesn't work for you too. If not, then there may be a bug specific to > > the version of SQL Relay you're using. What version is that, by the > > way? > > > > Dave > > > > > > On Thu, 2005-07-21 at 16:10 +0100, Ville Silventoinen wrote: > >> Hi Dave, > >> > >> Python len seems to be working correctly with pickled data. > >> > >> I did find out that cPickle.dumps(sdata) works ok. This generates string > >> representation of the pickled data, which doesn't contain a \0 character. > >> (I had a typo in my earlier test, the create procedure used string data, > >> the modify procedure used binary, which is why I thought neither dumps > >> worked.) > >> > >> If I use the HIGHEST_PROTOCOL with dumps, it generates binary data. This > >> seems to have a problem with inputBindBlob(), unless I'm still doing > >> something wrong. So if I am right, you should be able to recreate the > >> problem with something like this: > >> > >> sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', 3:'bar'}}} > >> ... > >> bdata = cPickle.dumps(sdata, 2) # uses HIGHEST_PROTOCOL > >> blen = len(bdata) > >> cur.inputBindBlob('colname', bdata, blen) > >> ... > >> # read the data by using normal select > >> ... > >> mydata = cPickle.loads(fields[0]) > >> # this throws EOFError (at least in my case) > >> > >> I think '' generates \x00 or \x0, which becomes EOF with inputBindBlob. > >> Perhaps it encodes \x00 as \0? Or maybe the problem is in the select? > >> Is it ok to use normal select to read blobs? > >> > >> Thanks, > >> Ville > >> > >> > >> On Thu, 21 Jul 2005, Firstworks/4access wrote: > >> > >>> Ville, > >>> > >>> I was actually looking at that last night. I'm believe you're on track. > >>> inputBind() does a strlen() of the string to decide how many characters > >>> to store in the database. strlen() interprets \0's as end-of-string > >>> markers, so only part of the data gets stored in the blob. Then, later > >>> when you fetch and unpickle it, only part of it gets unpickled. I > >>> believe the solution is to use inputBindBlob() or inputBindClob() rather > >>> than inputBind() to store the pickled data. inputBindBlob() and > >>> inputBindClob() take a length parameter and ignore \0's. > >>> > >>> Give it a try and let me know whether it works or not. > >>> > >>> Dave > >>> dav...@fi... > >>> > >>> On Thu, 2005-07-21 at 12:31 +0100, Ville Silventoinen wrote: > >>>> Hi, > >>>> > >>>> I'm using PySQLRClient from sqlrelay-0.36 (with rudiments-0.28.2) > >>>> to store blobs in Oracle 9.2.0 database. > >>>> > >>>> I'm not sure if this has been fixed in the recent sqlrelay release, > >>>> but I'm experiencing problems when I store a Python data structure > >>>> (dictionary object) to a blob using Pythons cPickle module. Everything > >>>> works great until one of the values in the pickled object is an empty > >>>> string (''). After that cPickle.load fails to read the data, it raises > >>>> EOFError exception. So I wonder if PySQLRClient interprets the pickled > >>>> '' as an end-of-file character? > >>>> > >>>> If I try loading/saving similar data structure to a file, it works ok. > >>>> > >>>> Thanks for any advice, > >>>> > >>>> Ville > >>>> > >>>> > >>>> > >>>> > >>>> ------------------------------------------------------- > >>>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > >>>> from IBM. Find simple to follow Roadmaps, straightforward articles, > >>>> informative Webcasts and more! Get everything you need to get up to > >>>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > >>>> _______________________________________________ > >>>> Sqlrelay-discussion mailing list > >>>> Sql...@li... > >>>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > >>>> > >>> > >>> > >>> > >>> ------------------------------------------------------- > >>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > >>> from IBM. Find simple to follow Roadmaps, straightforward articles, > >>> informative Webcasts and more! Get everything you need to get up to > >>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > >>> _______________________________________________ > >>> Sqlrelay-discussion mailing list > >>> Sql...@li... > >>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > >>> > >> > >> > >> ------------------------------------------------------- > >> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > >> from IBM. Find simple to follow Roadmaps, straightforward articles, > >> informative Webcasts and more! Get everything you need to get up to > >> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > >> _______________________________________________ > >> Sqlrelay-discussion mailing list > >> Sql...@li... > >> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > >> > > > > > > > > ------------------------------------------------------- > > SF.Net email is Sponsored by the Better Software Conference & EXPO September > > 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices > > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA > > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > > _______________________________________________ > > Sqlrelay-discussion mailing list > > Sql...@li... > > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > > > > ------------------------------------------------------- > SF.Net email is Sponsored by the Better Software Conference & EXPO September > 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > _______________________________________________ > Sqlrelay-discussion mailing list > Sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > |
From: David M. <dav...@fi...> - 2005-08-05 02:14:40
Attachments:
CSQLRelay.C
|
Well, I didn't get to look at it that night. Sorry about that :) I figured it out. getField() works but fields returned from getRow() don't. I fixed it though. If you replace src/api/python/CSQLRelay.C with the attached file and rebuild/reinstall, it will work. Dave On Thu, 2005-07-28 at 11:02 -0400, Firstworks/4access wrote: > Sorry, I forgot to mention. I tried cPickle.dumps(sdata) and > cPickle.dumps(sdata,2) and both worked for me. I wonder if there's a > bug in 0.36 that's causing the error. I'll give it a try tonight and > let you know what I find. > > Dave > > On Thu, 2005-07-28 at 09:28 +0100, Ville Silventoinen wrote: > > Hi Dave, > > > > thank you very much for putting your time into this. As I tried to explain > > in my earlier mail (I'm not very good in explaining things!), the problem > > happens when I use cPickle.dumps to generate a binary string, not a text > > string. You get a binary string by specifying a second parameter '2' > > (according to my source, Python Cookbook, 2nd ed): > > > > bdata=cPickle.dumps(sdata, 2) > > > > When I run your test script, it works, because cPickle.dumps(sdata) > > generates a text string. But when I do the above change, I get an error: > > > > {'spam': {'eggs': 'spamspam', 'answers': {1: '', 2: 'foo', 3: 'bar'}}} > > Traceback (most recent call last): > > File "./testsqlr.py", line 32, in ? > > mydata=cPickle.loads(fields[0]) > > EOFError > > > > It's not really necessary to use a binary string in my case, so I wouldn't > > give this problem a very high priority. The Python Cookbook states that > > using binary strings is "faster and takes up less space". > > > > I haven't had time to try your suggestion about using getField() and > > getFieldLength() for blobs. I'll try it in the next few days. > > > > My SQLRelay is version 0.36 with rudiments 0.28.2. > > > > Thanks again! > > > > Ville > > > > > > On Wed, 27 Jul 2005, David Muse wrote: > > > > > Ville, > > > > > > I have run some tests with my development version and the following > > > script works: > > > > > > #! /usr/bin/env python > > > > > > # Copyright (c) 2001 David Muse > > > # See the file COPYING for more information. > > > > > > from SQLRelay import PySQLRClient > > > import sys > > > import string > > > import cPickle > > > > > > con=PySQLRClient.sqlrconnection("localhost",8009,"/tmp/oracle8test.socket","oracle8test","oracle8test") > > > #con.debugOn() > > > cur=PySQLRClient.sqlrcursor(con) > > > > > > cur.sendQuery("drop table testtable"); > > > cur.sendQuery("create table testtable (col1 blob)") > > > > > > cur.prepareQuery("insert into testtable values(:val1)"); > > > sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', > > > 3:'bar'}}} > > > bdata=cPickle.dumps(sdata) > > > blen=len(bdata) > > > cur.inputBindBlob('val1',bdata,blen) > > > cur.executeQuery() > > > > > > cur.sendQuery("select * from testtable"); > > > mydata=cPickle.loads(cur.getField(0,0)) > > > print mydata > > > > > > cur.sendQuery("select * from testtable"); > > > fields=cur.getRow(0) > > > mydata=cPickle.loads(fields[0]) > > > print mydata > > > > > > cur.sendQuery("drop table testtable"); > > > > > > > > > It prints out a tuple identical to the one sdata is set to. See if it > > > doesn't work for you too. If not, then there may be a bug specific to > > > the version of SQL Relay you're using. What version is that, by the > > > way? > > > > > > Dave > > > > > > > > > On Thu, 2005-07-21 at 16:10 +0100, Ville Silventoinen wrote: > > >> Hi Dave, > > >> > > >> Python len seems to be working correctly with pickled data. > > >> > > >> I did find out that cPickle.dumps(sdata) works ok. This generates string > > >> representation of the pickled data, which doesn't contain a \0 character. > > >> (I had a typo in my earlier test, the create procedure used string data, > > >> the modify procedure used binary, which is why I thought neither dumps > > >> worked.) > > >> > > >> If I use the HIGHEST_PROTOCOL with dumps, it generates binary data. This > > >> seems to have a problem with inputBindBlob(), unless I'm still doing > > >> something wrong. So if I am right, you should be able to recreate the > > >> problem with something like this: > > >> > > >> sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', 3:'bar'}}} > > >> ... > > >> bdata = cPickle.dumps(sdata, 2) # uses HIGHEST_PROTOCOL > > >> blen = len(bdata) > > >> cur.inputBindBlob('colname', bdata, blen) > > >> ... > > >> # read the data by using normal select > > >> ... > > >> mydata = cPickle.loads(fields[0]) > > >> # this throws EOFError (at least in my case) > > >> > > >> I think '' generates \x00 or \x0, which becomes EOF with inputBindBlob. > > >> Perhaps it encodes \x00 as \0? Or maybe the problem is in the select? > > >> Is it ok to use normal select to read blobs? > > >> > > >> Thanks, > > >> Ville > > >> > > >> > > >> On Thu, 21 Jul 2005, Firstworks/4access wrote: > > >> > > >>> Ville, > > >>> > > >>> I was actually looking at that last night. I'm believe you're on track. > > >>> inputBind() does a strlen() of the string to decide how many characters > > >>> to store in the database. strlen() interprets \0's as end-of-string > > >>> markers, so only part of the data gets stored in the blob. Then, later > > >>> when you fetch and unpickle it, only part of it gets unpickled. I > > >>> believe the solution is to use inputBindBlob() or inputBindClob() rather > > >>> than inputBind() to store the pickled data. inputBindBlob() and > > >>> inputBindClob() take a length parameter and ignore \0's. > > >>> > > >>> Give it a try and let me know whether it works or not. > > >>> > > >>> Dave > > >>> dav...@fi... > > >>> > > >>> On Thu, 2005-07-21 at 12:31 +0100, Ville Silventoinen wrote: > > >>>> Hi, > > >>>> > > >>>> I'm using PySQLRClient from sqlrelay-0.36 (with rudiments-0.28.2) > > >>>> to store blobs in Oracle 9.2.0 database. > > >>>> > > >>>> I'm not sure if this has been fixed in the recent sqlrelay release, > > >>>> but I'm experiencing problems when I store a Python data structure > > >>>> (dictionary object) to a blob using Pythons cPickle module. Everything > > >>>> works great until one of the values in the pickled object is an empty > > >>>> string (''). After that cPickle.load fails to read the data, it raises > > >>>> EOFError exception. So I wonder if PySQLRClient interprets the pickled > > >>>> '' as an end-of-file character? > > >>>> > > >>>> If I try loading/saving similar data structure to a file, it works ok. > > >>>> > > >>>> Thanks for any advice, > > >>>> > > >>>> Ville > > >>>> > > >>>> > > >>>> > > >>>> > > >>>> ------------------------------------------------------- > > >>>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > > >>>> from IBM. Find simple to follow Roadmaps, straightforward articles, > > >>>> informative Webcasts and more! Get everything you need to get up to > > >>>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > > >>>> _______________________________________________ > > >>>> Sqlrelay-discussion mailing list > > >>>> Sql...@li... > > >>>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > >>>> > > >>> > > >>> > > >>> > > >>> ------------------------------------------------------- > > >>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > > >>> from IBM. Find simple to follow Roadmaps, straightforward articles, > > >>> informative Webcasts and more! Get everything you need to get up to > > >>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > > >>> _______________________________________________ > > >>> Sqlrelay-discussion mailing list > > >>> Sql...@li... > > >>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > >>> > > >> > > >> > > >> ------------------------------------------------------- > > >> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > > >> from IBM. Find simple to follow Roadmaps, straightforward articles, > > >> informative Webcasts and more! Get everything you need to get up to > > >> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > > >> _______________________________________________ > > >> Sqlrelay-discussion mailing list > > >> Sql...@li... > > >> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > >> > > > > > > > > > > > > ------------------------------------------------------- > > > SF.Net email is Sponsored by the Better Software Conference & EXPO September > > > 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices > > > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA > > > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > > > _______________________________________________ > > > Sqlrelay-discussion mailing list > > > Sql...@li... > > > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > > > > > > > > ------------------------------------------------------- > > SF.Net email is Sponsored by the Better Software Conference & EXPO September > > 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices > > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA > > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > > _______________________________________________ > > Sqlrelay-discussion mailing list > > Sql...@li... > > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > > > > > > ------------------------------------------------------- > SF.Net email is Sponsored by the Better Software Conference & EXPO September > 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > _______________________________________________ > Sqlrelay-discussion mailing list > Sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > |
From: Ville S. <vs...@eb...> - 2005-08-11 09:55:48
|
Hi Dave, I finally had a chance to apply the CSQLRelay.C fix. It works! Using the "cPickle.dumps(sdata, 2)" speeds up my Python methods around 60%, which is a nice improvement. Thank you very much for the fix. Best regards, Ville On Thu, 4 Aug 2005, David Muse wrote: > Well, I didn't get to look at it that night. Sorry about that :) > > I figured it out. getField() works but fields returned from getRow() > don't. I fixed it though. If you replace src/api/python/CSQLRelay.C > with the attached file and rebuild/reinstall, it will work. > > Dave > > On Thu, 2005-07-28 at 11:02 -0400, Firstworks/4access wrote: >> Sorry, I forgot to mention. I tried cPickle.dumps(sdata) and >> cPickle.dumps(sdata,2) and both worked for me. I wonder if there's a >> bug in 0.36 that's causing the error. I'll give it a try tonight and >> let you know what I find. >> >> Dave >> >> On Thu, 2005-07-28 at 09:28 +0100, Ville Silventoinen wrote: >>> Hi Dave, >>> >>> thank you very much for putting your time into this. As I tried to explain >>> in my earlier mail (I'm not very good in explaining things!), the problem >>> happens when I use cPickle.dumps to generate a binary string, not a text >>> string. You get a binary string by specifying a second parameter '2' >>> (according to my source, Python Cookbook, 2nd ed): >>> >>> bdata=cPickle.dumps(sdata, 2) >>> >>> When I run your test script, it works, because cPickle.dumps(sdata) >>> generates a text string. But when I do the above change, I get an error: >>> >>> {'spam': {'eggs': 'spamspam', 'answers': {1: '', 2: 'foo', 3: 'bar'}}} >>> Traceback (most recent call last): >>> File "./testsqlr.py", line 32, in ? >>> mydata=cPickle.loads(fields[0]) >>> EOFError >>> >>> It's not really necessary to use a binary string in my case, so I wouldn't >>> give this problem a very high priority. The Python Cookbook states that >>> using binary strings is "faster and takes up less space". >>> >>> I haven't had time to try your suggestion about using getField() and >>> getFieldLength() for blobs. I'll try it in the next few days. >>> >>> My SQLRelay is version 0.36 with rudiments 0.28.2. >>> >>> Thanks again! >>> >>> Ville >>> >>> >>> On Wed, 27 Jul 2005, David Muse wrote: >>> >>>> Ville, >>>> >>>> I have run some tests with my development version and the following >>>> script works: >>>> >>>> #! /usr/bin/env python >>>> >>>> # Copyright (c) 2001 David Muse >>>> # See the file COPYING for more information. >>>> >>>> from SQLRelay import PySQLRClient >>>> import sys >>>> import string >>>> import cPickle >>>> >>>> con=PySQLRClient.sqlrconnection("localhost",8009,"/tmp/oracle8test.socket","oracle8test","oracle8test") >>>> #con.debugOn() >>>> cur=PySQLRClient.sqlrcursor(con) >>>> >>>> cur.sendQuery("drop table testtable"); >>>> cur.sendQuery("create table testtable (col1 blob)") >>>> >>>> cur.prepareQuery("insert into testtable values(:val1)"); >>>> sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', >>>> 3:'bar'}}} >>>> bdata=cPickle.dumps(sdata) >>>> blen=len(bdata) >>>> cur.inputBindBlob('val1',bdata,blen) >>>> cur.executeQuery() >>>> >>>> cur.sendQuery("select * from testtable"); >>>> mydata=cPickle.loads(cur.getField(0,0)) >>>> print mydata >>>> >>>> cur.sendQuery("select * from testtable"); >>>> fields=cur.getRow(0) >>>> mydata=cPickle.loads(fields[0]) >>>> print mydata >>>> >>>> cur.sendQuery("drop table testtable"); >>>> >>>> >>>> It prints out a tuple identical to the one sdata is set to. See if it >>>> doesn't work for you too. If not, then there may be a bug specific to >>>> the version of SQL Relay you're using. What version is that, by the >>>> way? >>>> >>>> Dave >>>> >>>> >>>> On Thu, 2005-07-21 at 16:10 +0100, Ville Silventoinen wrote: >>>>> Hi Dave, >>>>> >>>>> Python len seems to be working correctly with pickled data. >>>>> >>>>> I did find out that cPickle.dumps(sdata) works ok. This generates string >>>>> representation of the pickled data, which doesn't contain a \0 character. >>>>> (I had a typo in my earlier test, the create procedure used string data, >>>>> the modify procedure used binary, which is why I thought neither dumps >>>>> worked.) >>>>> >>>>> If I use the HIGHEST_PROTOCOL with dumps, it generates binary data. This >>>>> seems to have a problem with inputBindBlob(), unless I'm still doing >>>>> something wrong. So if I am right, you should be able to recreate the >>>>> problem with something like this: >>>>> >>>>> sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', 3:'bar'}}} >>>>> ... >>>>> bdata = cPickle.dumps(sdata, 2) # uses HIGHEST_PROTOCOL >>>>> blen = len(bdata) >>>>> cur.inputBindBlob('colname', bdata, blen) >>>>> ... >>>>> # read the data by using normal select >>>>> ... >>>>> mydata = cPickle.loads(fields[0]) >>>>> # this throws EOFError (at least in my case) >>>>> >>>>> I think '' generates \x00 or \x0, which becomes EOF with inputBindBlob. >>>>> Perhaps it encodes \x00 as \0? Or maybe the problem is in the select? >>>>> Is it ok to use normal select to read blobs? >>>>> >>>>> Thanks, >>>>> Ville >>>>> >>>>> >>>>> On Thu, 21 Jul 2005, Firstworks/4access wrote: >>>>> >>>>>> Ville, >>>>>> >>>>>> I was actually looking at that last night. I'm believe you're on track. >>>>>> inputBind() does a strlen() of the string to decide how many characters >>>>>> to store in the database. strlen() interprets \0's as end-of-string >>>>>> markers, so only part of the data gets stored in the blob. Then, later >>>>>> when you fetch and unpickle it, only part of it gets unpickled. I >>>>>> believe the solution is to use inputBindBlob() or inputBindClob() rather >>>>>> than inputBind() to store the pickled data. inputBindBlob() and >>>>>> inputBindClob() take a length parameter and ignore \0's. >>>>>> >>>>>> Give it a try and let me know whether it works or not. >>>>>> >>>>>> Dave >>>>>> dav...@fi... >>>>>> >>>>>> On Thu, 2005-07-21 at 12:31 +0100, Ville Silventoinen wrote: >>>>>>> Hi, >>>>>>> >>>>>>> I'm using PySQLRClient from sqlrelay-0.36 (with rudiments-0.28.2) >>>>>>> to store blobs in Oracle 9.2.0 database. >>>>>>> >>>>>>> I'm not sure if this has been fixed in the recent sqlrelay release, >>>>>>> but I'm experiencing problems when I store a Python data structure >>>>>>> (dictionary object) to a blob using Pythons cPickle module. Everything >>>>>>> works great until one of the values in the pickled object is an empty >>>>>>> string (''). After that cPickle.load fails to read the data, it raises >>>>>>> EOFError exception. So I wonder if PySQLRClient interprets the pickled >>>>>>> '' as an end-of-file character? >>>>>>> >>>>>>> If I try loading/saving similar data structure to a file, it works ok. >>>>>>> >>>>>>> Thanks for any advice, >>>>>>> >>>>>>> Ville >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> ------------------------------------------------------- >>>>>>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >>>>>>> from IBM. Find simple to follow Roadmaps, straightforward articles, >>>>>>> informative Webcasts and more! Get everything you need to get up to >>>>>>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click >>>>>>> _______________________________________________ >>>>>>> Sqlrelay-discussion mailing list >>>>>>> Sql...@li... >>>>>>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> ------------------------------------------------------- >>>>>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >>>>>> from IBM. Find simple to follow Roadmaps, straightforward articles, >>>>>> informative Webcasts and more! Get everything you need to get up to >>>>>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click >>>>>> _______________________________________________ >>>>>> Sqlrelay-discussion mailing list >>>>>> Sql...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion >>>>>> >>>>> >>>>> >>>>> ------------------------------------------------------- >>>>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >>>>> from IBM. Find simple to follow Roadmaps, straightforward articles, >>>>> informative Webcasts and more! Get everything you need to get up to >>>>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click >>>>> _______________________________________________ >>>>> Sqlrelay-discussion mailing list >>>>> Sql...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion >>>>> >>>> >>>> >>>> >>>> ------------------------------------------------------- >>>> SF.Net email is Sponsored by the Better Software Conference & EXPO September >>>> 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices >>>> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA >>>> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf >>>> _______________________________________________ >>>> Sqlrelay-discussion mailing list >>>> Sql...@li... >>>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion >>>> >>> >>> >>> ------------------------------------------------------- >>> SF.Net email is Sponsored by the Better Software Conference & EXPO September >>> 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices >>> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA >>> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf >>> _______________________________________________ >>> Sqlrelay-discussion mailing list >>> Sql...@li... >>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion >>> >> >> >> >> ------------------------------------------------------- >> SF.Net email is Sponsored by the Better Software Conference & EXPO September >> 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices >> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA >> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf >> _______________________________________________ >> Sqlrelay-discussion mailing list >> Sql...@li... >> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion >> > |
From: David M. <dav...@fi...> - 2005-08-11 21:02:10
|
Yay! Glad it worked for you. 60% eh? definitely a nice improvement :) Dave On Thu, 2005-08-11 at 10:55 +0100, Ville Silventoinen wrote: > Hi Dave, > > I finally had a chance to apply the CSQLRelay.C fix. It works! > Using the "cPickle.dumps(sdata, 2)" speeds up my Python methods > around 60%, which is a nice improvement. > > Thank you very much for the fix. > > Best regards, > Ville > > > On Thu, 4 Aug 2005, David Muse wrote: > > > Well, I didn't get to look at it that night. Sorry about that :) > > > > I figured it out. getField() works but fields returned from getRow() > > don't. I fixed it though. If you replace src/api/python/CSQLRelay.C > > with the attached file and rebuild/reinstall, it will work. > > > > Dave > > > > On Thu, 2005-07-28 at 11:02 -0400, Firstworks/4access wrote: > >> Sorry, I forgot to mention. I tried cPickle.dumps(sdata) and > >> cPickle.dumps(sdata,2) and both worked for me. I wonder if there's a > >> bug in 0.36 that's causing the error. I'll give it a try tonight and > >> let you know what I find. > >> > >> Dave > >> > >> On Thu, 2005-07-28 at 09:28 +0100, Ville Silventoinen wrote: > >>> Hi Dave, > >>> > >>> thank you very much for putting your time into this. As I tried to explain > >>> in my earlier mail (I'm not very good in explaining things!), the problem > >>> happens when I use cPickle.dumps to generate a binary string, not a text > >>> string. You get a binary string by specifying a second parameter '2' > >>> (according to my source, Python Cookbook, 2nd ed): > >>> > >>> bdata=cPickle.dumps(sdata, 2) > >>> > >>> When I run your test script, it works, because cPickle.dumps(sdata) > >>> generates a text string. But when I do the above change, I get an error: > >>> > >>> {'spam': {'eggs': 'spamspam', 'answers': {1: '', 2: 'foo', 3: 'bar'}}} > >>> Traceback (most recent call last): > >>> File "./testsqlr.py", line 32, in ? > >>> mydata=cPickle.loads(fields[0]) > >>> EOFError > >>> > >>> It's not really necessary to use a binary string in my case, so I wouldn't > >>> give this problem a very high priority. The Python Cookbook states that > >>> using binary strings is "faster and takes up less space". > >>> > >>> I haven't had time to try your suggestion about using getField() and > >>> getFieldLength() for blobs. I'll try it in the next few days. > >>> > >>> My SQLRelay is version 0.36 with rudiments 0.28.2. > >>> > >>> Thanks again! > >>> > >>> Ville > >>> > >>> > >>> On Wed, 27 Jul 2005, David Muse wrote: > >>> > >>>> Ville, > >>>> > >>>> I have run some tests with my development version and the following > >>>> script works: > >>>> > >>>> #! /usr/bin/env python > >>>> > >>>> # Copyright (c) 2001 David Muse > >>>> # See the file COPYING for more information. > >>>> > >>>> from SQLRelay import PySQLRClient > >>>> import sys > >>>> import string > >>>> import cPickle > >>>> > >>>> con=PySQLRClient.sqlrconnection("localhost",8009,"/tmp/oracle8test.socket","oracle8test","oracle8test") > >>>> #con.debugOn() > >>>> cur=PySQLRClient.sqlrcursor(con) > >>>> > >>>> cur.sendQuery("drop table testtable"); > >>>> cur.sendQuery("create table testtable (col1 blob)") > >>>> > >>>> cur.prepareQuery("insert into testtable values(:val1)"); > >>>> sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', > >>>> 3:'bar'}}} > >>>> bdata=cPickle.dumps(sdata) > >>>> blen=len(bdata) > >>>> cur.inputBindBlob('val1',bdata,blen) > >>>> cur.executeQuery() > >>>> > >>>> cur.sendQuery("select * from testtable"); > >>>> mydata=cPickle.loads(cur.getField(0,0)) > >>>> print mydata > >>>> > >>>> cur.sendQuery("select * from testtable"); > >>>> fields=cur.getRow(0) > >>>> mydata=cPickle.loads(fields[0]) > >>>> print mydata > >>>> > >>>> cur.sendQuery("drop table testtable"); > >>>> > >>>> > >>>> It prints out a tuple identical to the one sdata is set to. See if it > >>>> doesn't work for you too. If not, then there may be a bug specific to > >>>> the version of SQL Relay you're using. What version is that, by the > >>>> way? > >>>> > >>>> Dave > >>>> > >>>> > >>>> On Thu, 2005-07-21 at 16:10 +0100, Ville Silventoinen wrote: > >>>>> Hi Dave, > >>>>> > >>>>> Python len seems to be working correctly with pickled data. > >>>>> > >>>>> I did find out that cPickle.dumps(sdata) works ok. This generates string > >>>>> representation of the pickled data, which doesn't contain a \0 character. > >>>>> (I had a typo in my earlier test, the create procedure used string data, > >>>>> the modify procedure used binary, which is why I thought neither dumps > >>>>> worked.) > >>>>> > >>>>> If I use the HIGHEST_PROTOCOL with dumps, it generates binary data. This > >>>>> seems to have a problem with inputBindBlob(), unless I'm still doing > >>>>> something wrong. So if I am right, you should be able to recreate the > >>>>> problem with something like this: > >>>>> > >>>>> sdata={'spam': {'eggs': 'spamspam', 'answers': {1:'', 2:'foo', 3:'bar'}}} > >>>>> ... > >>>>> bdata = cPickle.dumps(sdata, 2) # uses HIGHEST_PROTOCOL > >>>>> blen = len(bdata) > >>>>> cur.inputBindBlob('colname', bdata, blen) > >>>>> ... > >>>>> # read the data by using normal select > >>>>> ... > >>>>> mydata = cPickle.loads(fields[0]) > >>>>> # this throws EOFError (at least in my case) > >>>>> > >>>>> I think '' generates \x00 or \x0, which becomes EOF with inputBindBlob. > >>>>> Perhaps it encodes \x00 as \0? Or maybe the problem is in the select? > >>>>> Is it ok to use normal select to read blobs? > >>>>> > >>>>> Thanks, > >>>>> Ville > >>>>> > >>>>> > >>>>> On Thu, 21 Jul 2005, Firstworks/4access wrote: > >>>>> > >>>>>> Ville, > >>>>>> > >>>>>> I was actually looking at that last night. I'm believe you're on track. > >>>>>> inputBind() does a strlen() of the string to decide how many characters > >>>>>> to store in the database. strlen() interprets \0's as end-of-string > >>>>>> markers, so only part of the data gets stored in the blob. Then, later > >>>>>> when you fetch and unpickle it, only part of it gets unpickled. I > >>>>>> believe the solution is to use inputBindBlob() or inputBindClob() rather > >>>>>> than inputBind() to store the pickled data. inputBindBlob() and > >>>>>> inputBindClob() take a length parameter and ignore \0's. > >>>>>> > >>>>>> Give it a try and let me know whether it works or not. > >>>>>> > >>>>>> Dave > >>>>>> dav...@fi... > >>>>>> > >>>>>> On Thu, 2005-07-21 at 12:31 +0100, Ville Silventoinen wrote: > >>>>>>> Hi, > >>>>>>> > >>>>>>> I'm using PySQLRClient from sqlrelay-0.36 (with rudiments-0.28.2) > >>>>>>> to store blobs in Oracle 9.2.0 database. > >>>>>>> > >>>>>>> I'm not sure if this has been fixed in the recent sqlrelay release, > >>>>>>> but I'm experiencing problems when I store a Python data structure > >>>>>>> (dictionary object) to a blob using Pythons cPickle module. Everything > >>>>>>> works great until one of the values in the pickled object is an empty > >>>>>>> string (''). After that cPickle.load fails to read the data, it raises > >>>>>>> EOFError exception. So I wonder if PySQLRClient interprets the pickled > >>>>>>> '' as an end-of-file character? > >>>>>>> > >>>>>>> If I try loading/saving similar data structure to a file, it works ok. > >>>>>>> > >>>>>>> Thanks for any advice, > >>>>>>> > >>>>>>> Ville > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> ------------------------------------------------------- > >>>>>>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > >>>>>>> from IBM. Find simple to follow Roadmaps, straightforward articles, > >>>>>>> informative Webcasts and more! Get everything you need to get up to > >>>>>>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > >>>>>>> _______________________________________________ > >>>>>>> Sqlrelay-discussion mailing list > >>>>>>> Sql...@li... > >>>>>>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > >>>>>>> > >>>>>> > >>>>>> > >>>>>> > >>>>>> ------------------------------------------------------- > >>>>>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > >>>>>> from IBM. Find simple to follow Roadmaps, straightforward articles, > >>>>>> informative Webcasts and more! Get everything you need to get up to > >>>>>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > >>>>>> _______________________________________________ > >>>>>> Sqlrelay-discussion mailing list > >>>>>> Sql...@li... > >>>>>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > >>>>>> > >>>>> > >>>>> > >>>>> ------------------------------------------------------- > >>>>> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > >>>>> from IBM. Find simple to follow Roadmaps, straightforward articles, > >>>>> informative Webcasts and more! Get everything you need to get up to > >>>>> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click > >>>>> _______________________________________________ > >>>>> Sqlrelay-discussion mailing list > >>>>> Sql...@li... > >>>>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > >>>>> > >>>> > >>>> > >>>> > >>>> ------------------------------------------------------- > >>>> SF.Net email is Sponsored by the Better Software Conference & EXPO September > >>>> 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices > >>>> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA > >>>> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > >>>> _______________________________________________ > >>>> Sqlrelay-discussion mailing list > >>>> Sql...@li... > >>>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > >>>> > >>> > >>> > >>> ------------------------------------------------------- > >>> SF.Net email is Sponsored by the Better Software Conference & EXPO September > >>> 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices > >>> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA > >>> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > >>> _______________________________________________ > >>> Sqlrelay-discussion mailing list > >>> Sql...@li... > >>> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > >>> > >> > >> > >> > >> ------------------------------------------------------- > >> SF.Net email is Sponsored by the Better Software Conference & EXPO September > >> 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices > >> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA > >> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > >> _______________________________________________ > >> Sqlrelay-discussion mailing list > >> Sql...@li... > >> https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > >> > > > > > ------------------------------------------------------- > SF.Net email is Sponsored by the Better Software Conference & EXPO > September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf > _______________________________________________ > Sqlrelay-discussion mailing list > Sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlrelay-discussion > |