[Tutor] Mysql BLOB strangeness?

Brian Gustin brian at daviesinc.com
Sun Mar 19 18:39:16 CET 2006


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 at daviesinc.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 at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> !DSPAM:441d42ee268352025918492!
> 
> 


More information about the Tutor mailing list