renenglish
renenglish

Reputation: 728

How to know if it is unsigned of a field from mysql by MySQLdb

I use MySQLdb(a python library) to talk with mysql. Is there some way to get the field type using MySQLdb , and the most important thing is how can I know it is unsigned or not ?

I know we can use MYSQL_FIELD struct to get what I mentioned above using mysql C api. Is there something similar in MySQLdb ?

Thank you very much!

Upvotes: 1

Views: 95

Answers (2)

Eugene Yarmash
Eugene Yarmash

Reputation: 149823

You can get the field type from the INFORMATION_SCHEMA Tables, e.g.

SELECT COLUMN_NAME, COLUMN_TYPE
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE table_name = 'tbl_name'

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798744

No. There is no provision in MySQLdb (not even via _mysql) for calling mysql_fetch_fields(). You will either have to patch it in, get someone else to do it, or find some way to do it in SQL.

Upvotes: 1

Related Questions