1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: classes hashtables help.markup help.syntax io.streams.string
4 kernel sequences strings math ;
8 { $description "The database assigns a primary key to the object. The primary key is most likely a big integer, but is database-dependent." } ;
11 { $description "Allows a default value for a column to be provided." } ;
14 { $description "Ensures that a column is not null." } ;
17 { $description "Allows a column to be null." } ;
20 { $description "Makes a column a primary key. Only one column may be a primary key." } ;
23 { $description "Factor chooses a random number and tries to insert the tuple into the database with this number as its primary key. The default number of retries to find a unique random number is 10, though in practice it will almost certainly succeed on the first try." } ;
25 HELP: +user-assigned-id+
26 { $description "The user is responsible for choosing a primary key for tuples inserted with this database type. Keys must be unique or else the database will throw an error. Usually it is better to use a " { $link +db-assigned-id+ } "." } ;
28 HELP: <generator-bind>
29 { $values { "slot-name" object } { "key" object } { "generator-singleton" object } { "type" object } { "generator-bind" generator-bind } }
30 { $description "An internal constructor for creating objects containing parameters used for binding generated values to a tuple query." } ;
33 { $values { "key" object } { "type" object } { "value" object } { "literal-bind" literal-bind } }
34 { $description "An internal constructor for creating objects containing parameters used for binding literal values to a tuple query." } ;
37 { $description "A 64-bit integer. Whether this number is signed or unsigned depends on the database backend." } ;
40 { $description "A byte array." } ;
43 { $description "Either true or false." } ;
46 { $description "A date without a time component." } ;
49 { $description "A date and a time." } ;
52 { $description "Corresponds to Factor's 64-bit floating-point numbers." } ;
55 { $description "A serialized Factor object." } ;
58 { $description "A small integer, at least 32 bits in length. Whether this number is signed or unsigned depends on the database backend." } ;
61 { $description "The SQL null type." } ;
64 { $description "A real number of unlimited precision. May not be supported on all databases." } ;
66 HELP: SIGNED-BIG-INTEGER
67 { $description "For portability, if a number is known to be 64bit and signed, then this datatype may be used. Some databases, like SQLite, cannot store arbitrary bignums as BIGINT types. If storing arbitrary bignums, use " { $link FACTOR-BLOB } "." } ;
70 { $description "Stores a string that is longer than a " { $link VARCHAR } ". SQLite uses this type for strings; it does not handle " { $link VARCHAR } " strings." } ;
73 { $description "A timestamp without a date component." } ;
76 { $description "A Factor timestamp." } ;
78 HELP: UNSIGNED-BIG-INTEGER
79 { $description "For portability, if a number is known to be 64bit, then this datatype may be used. Some databases, like SQLite, cannot store arbitrary bignums as BIGINT types. If storing arbitrary bignums, use " { $link FACTOR-BLOB } "." } ;
81 { INTEGER SIGNED-BIG-INTEGER UNSIGNED-BIG-INTEGER } related-words
84 { $description "A Factor " { $link "urls" } " object." } ;
87 { $description "The SQL varchar type. This type can take an integer as an argument." }
88 { $examples { $unchecked-example "{ VARCHAR 256 }" "" } } ;
90 HELP: user-assigned-id-spec?
92 { "specs" "a sequence of SQL specs" }
94 { $description "Tests if any of the SQL specs has the type " { $link +user-assigned-id+ } "." } ;
98 { "spec" "a SQL spec" } { "obj" object } }
99 { $description "A generic word that lets a database construct a literal binding." } ;
103 { "spec" "a SQL spec" } }
104 { $description "A generic word that lets a database output a binding." } ;
106 HELP: db-assigned-id-spec?
108 { "specs" "a sequence of SQL specs" }
109 { "?" "a boolean" } }
110 { $description "Tests if any of the SQL specs has the type " { $link +db-assigned-id+ } "." } ;
112 HELP: find-primary-key
114 { "specs" "a sequence of SQL specs" }
115 { "seq" "a sequence of SQL specs" } }
116 { $description "Returns the rows from the SQL specs array that are part of the primary key. Composite primary keys are supported, so this word must return a sequence." }
117 { $notes "This is a low-level word." } ;
121 { "name" "a slot name" } { "tuple" tuple }
122 { "value" "the value stored in the slot" } }
123 { $description "Returns the value stored in a tuple slot, where the tuple slot is a string." } ;
127 { "type" "a SQL type" } }
128 { $description "Throws an error containing a SQL type that is unsupported or the result of a typo." } ;
132 { "spec" "a SQL spec" } }
133 { $description "Normalizes a SQL spec." } ;
137 { "string" string } { "tuple" tuple }
139 { $description "Returns the offset of a tuple slot accessed by name." } ;
143 { "spec" "a SQL spec" }
144 { "?" "a boolean" } }
145 { $description "Returns true if a SQL spec is a primary key." } ;
149 { "spec" "a SQL spec" }
150 { "?" "a boolean" } }
151 { $description "Returns true if a SQL spec is a relation." } ;
153 HELP: unknown-modifier
154 { $values { "modifier" string } }
155 { $description "Throws an error containing an unknown SQL modifier." } ;
157 ARTICLE: "db.types" "Database types"
158 "The " { $vocab-link "db.types" } " vocabulary maps Factor types to database types." $nl
165 "Null and boolean types:"
191 "Factor byte-arrays:"
192 { $subsections BLOB }
193 "Arbitrary Factor objects:"
194 { $subsections FACTOR-BLOB }
196 { $subsections URL } ;