ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
Re: [Tutor] Mysql BLOB strangeness?
by Brian Gustin other posts by this author
Mar 19 2006 9:39AM messages near this date
Re: [Tutor] Mysql BLOB strangeness? | Re: [Tutor] Mysql BLOB strangeness?
OK so I guess you know what you need to do now :)  something like this 
perhaaps :

(modified your original code)

reportlist = query(reportquery)
mystring = '<p> '
for row in reportlist:
	id = row[0]
	title = row[1]
	content = row[2]
	published = row[3]
	mystring = mystring+id+"\t"+title+"\t"+content+"\t"+published+"</p> "

print mystring

should get you the data - you may want to force the values to str() type 
  just in case.. anyhow..  when you append an array to an array, you 
have a multi-dimensional array, so when you iterate, you need to handle 
two arrays, in essence.. what python is doing is just what it told you 
to do - convert the multi dimensional list object into a string and 
print it. :) , therefore, the output would be 
array("listitem","listitem") basically :) you need to extract your list 
elements and convert those to strings, then you can work with the whole 
as a string :) otherwise,

do print reportlist  (without the str() stuff) and you will print out 
the entire list of data so you can see what you will be working with :)


what I would do is a function that returns the result set, instead, and 
then iterate over that list object..

Bri!


Adam Cripps wrote:
>  On 3/18/06, Brian Gustin <brian@[...].com> wrote:
>  
> >Oh. just found the original question.. :)
> >
> >OK perhaps this would be more helpful if you were to manually query
> >mysql on command line and paste the results it outputs here.
> >
> >what I am betting is your method to get the data out of teh query is
> >doing exactly what you tell it to.. :)
> >
> >but this hinges on the answer to "what is the original row of data
> >returned by commandline mysql query"
> >
> >keep in mind Mysql returns a result set as an array (a list or
> >dictionary, when it is associative, if you will)
> >
> >what your code is doing is taking the row (array) and appending it to an
> >additional list..
> >
> >and where you print the whole, you are basically printing out the
> >multi-dimensional array, and I am betting the *last element* returned
> >non-null in the mysql query is the content field.. :)
> >
> >but again, it depends on what the actual content is..
> >
> >run these two in mysql command line:
> >
> >mysql> show create table report;
> >mysql> select * from report limit 1;
> >
> >and let me know the results.. :)
> >
> >I doubt that blob vs. text has anything to do with this issue :)
> >
> >Bri!
>  
>  
>  Thanks again Bri, for both your responses.
>  
>  As requested -
>  
>  mysql> show create table report:
>  | report | CREATE TABLE `report` (
>    `id` int(11) NOT NULL auto_increment,
>    `title` varchar(255) default NULL,
>    `content` blob,
>    `author` int(10) default NULL,
>    `published` varchar(10) default 'n',
>    `rejected` char(1) default NULL,
>    PRIMARY KEY  (`id`)
>  ) TYPE=MyISAM |
>  
>  mysql> select * from report limit 1;
>  +----+-------+-----------------+--------+-----------+----------+
>  | id | title | content         | author | published | rejected |
>  +----+-------+-----------------+--------+-----------+----------+
>  |  1 | Test  | This is a test  |      0 | n         | NULL     |
>  +----+-------+-----------------+--------+-----------+----------+
>  1 row in set (0.02 sec)
>  (shame this doesn't monospace in Gmail)
>  
>  
>  You are right to bet that the last non-null field (part of the array)
>  is the content field (select id, title, content from report)
>  Adam
>  --
>  http://www.monkeez.org
>  PGP key: 0x7111B833
>  _______________________________________________
>  Tutor maillist  -  Tutor@[...].org
>  http://mail.python.org/mailman/listinfo/tutor
>  
>  !DSPAM:441d42ee268352025918492!
>  
>  
_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Adam Cripps
Brian Gustin
Adam Cripps
Brian Gustin
Adam Cripps
Kent Johnson
Brian Gustin
Adam Cripps
Kent Johnson
Adam Cripps
Liam Clarke
Brian Gustin
Adam Cripps
Hugo González Monteverde

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved