English 中文(简体)
描述与数据库外地类型有关的“类型-代码”通信
原标题:cursor.description "type_code" correspondence with database field types

采用MySQL背端,基本上想确定从 cur形形形形形形形形形色色色的表。 说明

我得到的是不同的数字......并且把我的表格与类型——密码价值相比较,我可以人工整理一套信函......但我比我的沙尔书(Beazley)所记载的类型物体多得多,即:可疑交易报告、BINear、NUMBER、DATET、ROWID。

因此,我假定存在不同的类型,即向DECIMAL、UNSignED INT等提供编码,但我感到惊讶的是,不能在这里或一般在网上发现任何信息。

顺便提一下,我想做的是使输入过程自动化(例如,与MySQL表格连接的GUI电网)确定该列表格预期的数据类型,并 par子和检查它,以确定这是否具有法律价值。

最佳回答

页: 1 DB-API specification 。

类型——代码必须比较等于以下定义的类型物体之一。

这里的陷阱是,可能有多种不同的类型的代码,它们都与同类物体相提并论。

>>> MySQLdb.constants.FIELD_TYPE.TIMESTAMP
7
>>> MySQLdb.constants.FIELD_TYPE.DATETIME
12
>>> MySQLdb.constants.FIELD_TYPE.TIMESTAMP==MySQLdb.DATETIME
True
>>> MySQLdb.constants.FIELD_TYPE.DATETIME==MySQLdb.DATETIME
True
>>> MySQLdb.DATETIME
DBAPISet([12, 7])

(如果执行这一魔法,将在关于非银-亚普切特的亚西佩奇的说明中概述。) 较常规的接口可能已经与次类进行。

这使MySQLdb能够提供关于该栏的更丰富信息,而不只是该栏是否为时日型,同时仍然允许对一个阵列进行简单测试。

当然,如果你开始比较,而不是 MySQLdb.constants.FIELD_TYPE几类产品直接依赖MySQLdb功能,从港口到其他数据库。

问题回答

如果你有兴趣了解如何绘制地图以描述:

>>> ft = MySQLdb.constants.FIELD_TYPE
>>> d = {getattr(ft, k): k for k in dir(ft) if not k.startswith( _ )}
>>> d
{0:  DECIMAL ,
 1:  TINY ,
 2:  SHORT ,
 3:  LONG ,
 4:  FLOAT ,
 5:  DOUBLE ,
 6:  NULL ,
 7:  TIMESTAMP ,
 8:  LONGLONG ,
 9:  INT24 ,
 10:  DATE ,
 11:  TIME ,
 12:  DATETIME ,
 13:  YEAR ,
 14:  NEWDATE ,
 15:  VARCHAR ,
 16:  BIT ,
 246:  NEWDECIMAL ,
 247:  INTERVAL ,
 248:  SET ,
 249:  TINY_BLOB ,
 250:  MEDIUM_BLOB ,
 251:  LONG_BLOB ,
 252:  BLOB ,
 253:  VAR_STRING ,
 254:  STRING ,
 255:  GEOMETRY }

如果您使用<代码>MySQLdb,则使用<代码>。 缩略语

>>> print dir(MySQLdb.constants.FIELD_TYPE)
[ BIT ,  BLOB ,  CHAR ,  DATE ,  DATETIME ,  DECIMAL ,  DOUBLE ,  ENUM , 
  FLOAT ,  GEOMETRY ,  INT24 ,  INTERVAL ,  LONG ,  LONGLONG ,  LONG_BLOB , 
  MEDIUM_BLOB ,  NEWDATE ,  NEWDECIMAL ,  NULL ,  SET ,  SHORT ,  STRING , 
  TIME ,  TIMESTAMP ,  TINY ,  TINY_BLOB ,  VARCHAR ,  VAR_STRING ,  YEAR ,
  __builtins__ ,  __doc__ ,  __file__ ,  __name__ ,  __package__ ]

例如,<代码>5的类型代码表示,这是MySQL的两倍。

>>> MySQLdb.constants.FIELD_TYPE.DOUBLE 
5

http://mysql-python.sourceforge.net/MySQLdb.html” rel=“nofollow”>documentation





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签