0

私の知る限り、標準の Python DB API は、結果行セットの正確な SQL タイプ情報を提供しません。

int、str ... のような切り詰められた python 型ではなく、結果行セットの正確な SQL 型と tinyint、bigint、nvarchar(100) などのより詳細な情報を取得する方法はありますか?

移植性やモジュールの依存関係は重要ではないと思います-何かがうまくいくだけです。(私はWindows、MS-SQLで作業しています。)

4

1 に答える 1

1

クエリの後に使用.descriptionして、特にデータ型に関する情報を取得します。

cursor.execute('select some_column from some_table')
print cursor.description

。説明

        This read-only attribute is a sequence of 7-item
        sequences.  

        Each of these sequences contains information describing
        one result column: 

          (name, 
           type_code, 
           display_size,
           internal_size, 
           precision, 
           scale, 
           null_ok)
于 2012-07-02T10:55:15.840 に答える