問題描述
有沒有辦法在 SQLite 中定義包含 SQLite 支持的任何數(shù)據(jù)類型的列類型?
Is there a way to define a column type in SQLite that holds any datatype that SQLite supports?
我有無符號(hào)字符、有符號(hào)字符、無符號(hào)整數(shù)、有符號(hào)整數(shù)、UTF-8 字符和 blob,我想將它們填充到單個(gè)列中.
I have unsigned chars, signedchars, unsigned ints, signed ints, UTF-8 chars and blobs that I want to populate in a single column.
也歡迎參考任何文獻(xiàn).
推薦答案
只是不要在列聲明中放類型,所以它沒有親和性
Just don't put a type in the column declaration, so it has NONE affinity
create table my_table(my_col);
SQLite 有一個(gè)獨(dú)特的動(dòng)態(tài)類型系統(tǒng).它具有按值類型,但如果您指定列類型,SQLite 將確定類型關(guān)聯(lián)(TEXT、NUMERIC、INTEGER、REAL、NONE).然后它嘗試將每個(gè)值強(qiáng)制為該關(guān)聯(lián).
SQLite has a unique dynamic typing system. It has per-value typing, but if you specify a column type, SQLite will determine a type affinity (TEXT, NUMERIC, INTEGER, REAL, NONE). It then attempts to coerce each value to that affinity.
實(shí)際支持的類型有 NULL、INTEGER、REAL、TEXT、BLOB.有關(guān)詳細(xì)信息,請(qǐng)參閱 SQLite 版本 3 中的數(shù)據(jù)類型.
The actual supported types are NULL, INTEGER, REAL, TEXT, BLOB. See Datatypes in SQLite Version 3 for more information.
這篇關(guān)于定義“變體"SQLite 中的列類型?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!