Getting Default Values Out of MySQL
MRAB
python at mrabarnett.plus.com
Sat Dec 12 11:38:41 EST 2009
Victor Subervi wrote:
>
>
> On Sat, Dec 12, 2009 at 10:54 AM, Carsten Haese <carsten.haese at gmail.com
> <mailto:carsten.haese at gmail.com>> wrote:
>
> Victor Subervi wrote:
> > Hi;
> > I'm using MySQLdb. If I do a
> > cursor.execute('describe myTable;')
> > it gives me all sorts of data but not my default values.
>
> That function call doesn't "give" any data at all, except for the
> rowcount (which would be the number of columns in the table).
>
>
> Really?
>
> cursor.execute('describe %s;' % store)
> storeDescription = cursor.fetchall()
> print storeDescription
>
> Prints out this:
>
> (('ID', 'tinyint(5) unsigned', 'NO', 'PRI', None, 'auto_increment'),
> ('SKU', 'varchar(40)', 'NO', 'UNI', None, ''), ('Category',
> 'varchar(40)', 'YES', '', None, ''), ('Name', 'varchar(50)', 'NO', '',
> None, ''), ('Title', 'varchar(100)', 'NO', '', None, ''),
> ('Description', 'mediumtext', 'NO', '', None, ''), ('Price',
> 'float(8,2)', 'YES', '', None, ''), ('SortFactor', 'int(4)', 'YES', '',
> '500', ''), ('Availability', 'tinyint(1)', 'NO', '', None, ''),
> ('ShipFlatFee', 'float(5,2)', 'NO', '', '10.00', ''),
> ('ShipPercentPrice', 'tinyint(2) unsigned', 'NO', '', '5', ''),
> ('ShipPercentWeight', 'tinyint(2) unsigned', 'NO', '', '2', ''),
> ('Associations', 'varchar(40)', 'NO', '', None, ''), ('TempPrice',
> 'float(7,2)', 'NO', '', None, ''), ('LastDatePrice', 'date', 'NO', '',
> None, ''), ('Weight', 'float(7,2)', 'NO', '', None, ''), ('Metal',
> "enum('14k gold','18k gold','white
> gold','silver','tungsten','titanium')", 'NO', '', None, ''),
> ('PercentMetal', 'tinyint(2) unsigned', 'NO', '', None, ''), ('pic1',
> 'blob', 'YES', '', None, ''), ('pic2', 'blob', 'YES', '', None, ''),
> ('sizes',
> "set('Extra-small','Small','Medium','Large','XLarge','XXLarge','XXXLarge')",
> 'YES', '', None, ''), ('colorsShadesNumbersShort',
> "set('blue:333399','gray:465945','purple:50404D','navy-blue:CC7722','fuchsia:FF77FF','aqua:7FFFD4','maroon:B03060','black:0000FF','yellow:9ACD32','teal:E2725B','olive:6B8E23','green:00A550','white:0F4D92','silver:708090','red:FE2712','lime:32CD32')",
> 'YES', '', None, ''))
>
> In my version of MySQL, he default value is in the fifth column of the
> result set.
>
>
> Nice. As you can see, I only get 4 columns by default. How do I get the
> fifth?
>
That's strange, I count 6!
For example, the first field has the following columns:
1. 'ID'
2. 'tinyint(5) unsigned'
3. 'NO'
4. 'PRI'
5. None
6. 'auto_increment'
More information about the Python-list
mailing list