{"id":78,"date":"2016-02-12T11:07:03","date_gmt":"2016-02-12T11:07:03","guid":{"rendered":"https:\/\/ibex.tech\/csharp\/?p=78"},"modified":"2022-02-17T06:24:15","modified_gmt":"2022-02-17T06:24:15","slug":"columns-general","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/c-sharp\/databases\/sqlite\/columns\/columns-general","title":{"rendered":".Columns General"},"content":{"rendered":"<p>\n\tSQLite&nbsp;much more simplistic data types compared to SQL. &nbsp;The datatype limitations can be cumbersome&nbsp;especially if you add time durations,&nbsp;dates&nbsp;etc as&nbsp;SQLite has very few built-in functions for these. The up side however is that SQLite&nbsp;provides an easy way to make your own built&nbsp;in functions for adding things like&nbsp;time durations (the sqlite3_create_function library function). You use that facility in place of traditional stored procedures.\n<\/p>\n<p>\n\tA SQLite column does not have a type requirement, but it does have a type preference, called an affinity. &nbsp;What this means is that under the hood&nbsp;sometimes SQLite will change the type of a value to fit match the affinity of the column, but you usually don&#39;t need to know this if you stick to storing an INTEGER in an INTEGER column, a REAL in a REAL column, etc.\n<\/p>\n<h4>\n\tData Types<br \/>\n<\/h4>\n<p>\n\t<a href=\"https:\/\/www.sqlite.org\/datatype3.html\">https:\/\/www.sqlite.org\/datatype3.html<\/a>\n<\/p>\n<p>\n\tSQLite 3 values can be one of the following types:\n<\/p>\n<p style=\"margin-left: 40px;\">\n\tTEXT\n<\/p>\n<p style=\"margin-left: 80px;\">\n\tStores all data using storage classes NULL, TEXT or BLOB. If numerical data is inserted into a column with TEXT affinity it is converted into text form before being stored.\n<\/p>\n<p style=\"margin-left: 80px;\">\n\tDeclare as a type that includes the characters:&nbsp;&quot;CHAR&quot;, &quot;CLOB&quot;, or &quot;TEXT&quot;<br \/>\n\tNotice that the type VARCHAR contains the string &quot;CHAR&quot; and is thus assigned TEXT affinity.\n<\/p>\n<p style=\"margin-left: 80px;\">\n\tLength &#8211; Specifying the length of a TEXT column is allowed but the value is ignored (You can declare a VARCHAR(10) and SQLite will be happy to store a 500-million character string there). &nbsp; There is no max length limitation for text.\n<\/p>\n<p style=\"margin-left: 40px;\">\n\tNUMERIC\n<\/p>\n<p style=\"margin-left: 80px;\">\n\tMay contain values using all five storage classes. When text data is inserted into a NUMERIC column, the storage class of the text is converted to INTEGER or REAL (in order of preference) if such conversion is lossless and reversible. For conversions between TEXT and REAL storage classes, SQLite considers the conversion to be lossless and reversible if the first 15 significant decimal digits of the number are preserved. If the lossless conversion of TEXT to INTEGER or REAL is not possible then the value is stored using the TEXT storage class. No attempt is made to convert NULL or BLOB values.\n<\/p>\n<p style=\"margin-left: 80px;\">\n\tDeclare as: anythign other than the other declaration character definitions, or simple &quot;NUMERIC&quot;\n<\/p>\n<p style=\"margin-left: 40px;\">\n\tINTEGER\n<\/p>\n<p style=\"margin-left: 80px;\">\n\tBehaves the same as a column with NUMERIC affinity. The difference between INTEGER and NUMERIC affinity is only evident in a CAST expression.<br \/>\n\tSigned integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.\n<\/p>\n<p style=\"margin-left: 80px;\">\n\tDeclare as a type that includes the characters: &quot;INT&quot;\n<\/p>\n<p style=\"margin-left: 40px;\">\n\tREAL\n<\/p>\n<p style=\"margin-left: 80px;\">\n\tBehaves like a column with NUMERIC affinity except that it forces integer values into floating point representation.<br \/>\n\t(As an internal optimization, small floating point values with no fractional component and stored in columns with REAL affinity are written to disk as integers in order to take up less space and are automatically converted back into floating point as the value is read out. This optimization is completely invisible at the SQL level and can only be detected by examining the raw bits of the database file.)\n<\/p>\n<p style=\"margin-left: 80px;\">\n\tDeclare as a type that includes the characters:&nbsp;&quot;REAL&quot;, &quot;FLOA&quot;, or &quot;DOUB&quot;&nbsp;\n<\/p>\n<p style=\"margin-left: 40px;\">\n\tNONE\n<\/p>\n<p style=\"margin-left: 80px;\">\n\tDoes not prefer one storage class over another and no attempt is made to coerce data from one storage class into another.\n<\/p>\n<p style=\"margin-left: 80px;\">\n\tDeclare as a type that includes the characters:&nbsp;&quot;BLOB&quot; or don&#39;t&nbsp;specify a type\n<\/p>\n<h4>\n\tConversion from more common SQL data types (SQLite&nbsp;&#39;Affinity&#39;)<br \/>\n<\/h4>\n<p>\n\t<a href=\"http:\/\/www.electronic-designer.co.uk\/wp-content\/uploads\/sites\/12\/sqlite_affinity_examples.png\" rel=\"noopener\" style=\"\" target=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" alt=\"sqlite_affinity_examples\" class=\"size-full wp-image-1251 alignnone\" height=\"596\" src=\"http:\/\/www.electronic-designer.co.uk\/wp-content\/uploads\/sites\/12\/sqlite_affinity_examples.png\" style=\"\" title=\"\" width=\"374\" \/><\/a>\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQLite&nbsp;much more simplistic data types compared to SQL. &nbsp;The datatype limitations can be cumbersome&nbsp;especially if you add time durations,&nbsp;dates&nbsp;etc as&nbsp;SQLite has very few built-in functions for these. The up side however is that SQLite&nbsp;provides an easy way to make your own built&nbsp;in functions for adding things like&nbsp;time durations (the sqlite3_create_function library function). You use that [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-78","post","type-post","status-publish","format-standard","hentry","category-columns"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=78"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/78\/revisions"}],"predecessor-version":[{"id":520,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/78\/revisions\/520"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}