fix potential infinite loop, minor docs updates

db4
Doug Coleman 2008-09-24 22:24:34 -05:00
parent 2a435b154f
commit 5be907e857
5 changed files with 30 additions and 42 deletions

View File

@ -116,7 +116,7 @@ HELP: execute-statement*
HELP: execute-statement HELP: execute-statement
{ $values { "statement" statement } } { $values { "statement" statement } }
{ $description } ; { $description "" } ;
ARTICLE: "db" "Database library" ARTICLE: "db" "Database library"
{ $subsection "db-custom-database-combinators" } { $subsection "db-custom-database-combinators" }

View File

@ -80,11 +80,14 @@ GENERIC: execute-statement* ( statement type -- )
M: object execute-statement* ( statement type -- ) M: object execute-statement* ( statement type -- )
drop query-results dispose ; drop query-results dispose ;
: execute-one-statement ( statement -- )
dup type>> execute-statement* ;
: execute-statement ( statement -- ) : execute-statement ( statement -- )
dup sequence? [ dup sequence? [
[ execute-statement ] each [ execute-one-statement ] each
] [ ] [
dup type>> execute-statement* execute-one-statement
] if ; ] if ;
: bind-statement ( obj statement -- ) : bind-statement ( obj statement -- )

View File

@ -518,6 +518,7 @@ string-encoding-test "STRING_ENCODING_TEST" {
! [ ] [ T{ exam f f "Kenny" 60 } insert-tuple ] unit-test ! [ ] [ T{ exam f f "Kenny" 60 } insert-tuple ] unit-test
! [ ] [ T{ exam f f "Cartman" 41 } insert-tuple ] unit-test ! [ ] [ T{ exam f f "Cartman" 41 } insert-tuple ] unit-test
[ ] [ 10 [ random-exam insert-tuple ] times ] unit-test [ ] [ 10 [ random-exam insert-tuple ] times ] unit-test
[ 5 ] [ <query> T{ exam { score T{ interval { from { 0 t } } { to { 100 t } } } } } >>tuple 5 >>limit select-tuples length ] unit-test
! [ ] [ T{ exam { name "Kenny" } } >query ] unit-test ! [ ] [ T{ exam { name "Kenny" } } >query ] unit-test
! [ ] [ query ] unit-test ! [ ] [ query ] unit-test
; ;

View File

@ -1,14 +1,8 @@
! Copyright (C) 2008 Doug Coleman. ! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: classes hashtables help.markup help.syntax io.streams.string kernel sequences strings ; USING: classes hashtables help.markup help.syntax io.streams.string kernel sequences strings db.tuples math ;
IN: db.types IN: db.types
HELP: (lookup-type)
{ $values
{ "obj" object }
{ "string" string } }
{ $description "" } ;
HELP: +autoincrement+ HELP: +autoincrement+
{ $description "" } ; { $description "" } ;
@ -55,7 +49,7 @@ HELP: <low-level-binding>
{ $description "" } ; { $description "" } ;
HELP: BIG-INTEGER HELP: BIG-INTEGER
{ $description "A 64-bit integer." } ; { $description "A 64-bit integer. Whether this number is signed or unsigned depends on the database backend." } ;
HELP: BLOB HELP: BLOB
{ $description "A serialized Factor object. The database library automatically serializes the object for a SQL insert or update and deserializes it on a tuple query." } ; { $description "A serialized Factor object. The database library automatically serializes the object for a SQL insert or update and deserializes it on a tuple query." } ;
@ -73,13 +67,13 @@ HELP: DOUBLE
{ $description "Corresponds to Factor's 64bit floating-point numbers." } ; { $description "Corresponds to Factor's 64bit floating-point numbers." } ;
HELP: FACTOR-BLOB HELP: FACTOR-BLOB
{ $description "" } ; { $description "A serialized Factor object." } ;
HELP: INTEGER HELP: INTEGER
{ $description "" } ; { $description "A small integer, at least 32 bits in length. Whether this number is signed or unsigned depends on the database backend." } ;
HELP: NULL HELP: NULL
{ $description "" } ; { $description "The SQL null type." } ;
HELP: REAL HELP: REAL
{ $description "" } ; { $description "" } ;
@ -94,16 +88,18 @@ HELP: TIME
{ $description "" } ; { $description "" } ;
HELP: TIMESTAMP HELP: TIMESTAMP
{ $description "" } ; { $description "A Factor timestamp." } ;
HELP: UNSIGNED-BIG-INTEGER HELP: UNSIGNED-BIG-INTEGER
{ $description "" } ; { $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 } "." } ;
{ INTEGER SIGNED-BIG-INTEGER UNSIGNED-BIG-INTEGER } related-words
HELP: URL HELP: URL
{ $description "" } ; { $description "A Factor " { $link "urls" } " object." } ;
HELP: VARCHAR HELP: VARCHAR
{ $description "" } ; { $description "The SQL varchar type. This type can take an integer as an argument." } ;
HELP: assigned-id-spec? HELP: assigned-id-spec?
{ $values { $values
@ -135,18 +131,19 @@ HELP: db-assigned-id-spec?
HELP: find-primary-key HELP: find-primary-key
{ $values { $values
{ "specs" null } { "specs" "an array of sql-specs" }
{ "obj" object } } { "obj" object } }
{ $description "" } ; { $description "Returns the row from the sql-specs array that was defined by " { $link define-persistent } "." }
{ $notes "This is a low-level word." } ;
HELP: generator-bind HELP: generator-bind
{ $description "" } ; { $description "" } ;
HELP: get-slot-named HELP: get-slot-named
{ $values { $values
{ "name" null } { "obj" object } { "name" "a slot name" } { "tuple" tuple }
{ "value" null } } { "value" "the value stored in the slot" } }
{ $description "" } ; { $description "Returns the value stored in a tuple slot, where the tuple slot is a string." } ;
HELP: join-space HELP: join-space
{ $values { $values
@ -192,23 +189,11 @@ HELP: normalize-spec
{ "spec" null } } { "spec" null } }
{ $description "" } ; { $description "" } ;
HELP: number>string*
{ $values
{ "n/string" null }
{ "string" string } }
{ $description "" } ;
HELP: offset-of-slot HELP: offset-of-slot
{ $values { $values
{ "string" string } { "obj" object } { "string" string } { "tuple" tuple }
{ "n" null } } { "n" integer } }
{ $description "" } ; { $description "Returns the offset of a tuple slot accessed by name." } ;
HELP: paren
{ $values
{ "string" string }
{ "new-string" null } }
{ $description "" } ;
HELP: persistent-table HELP: persistent-table
{ $values { $values
@ -294,7 +279,6 @@ ARTICLE: "db.types" "Database types"
{ $subsection BLOB } { $subsection BLOB }
{ $subsection FACTOR-BLOB } { $subsection FACTOR-BLOB }
"Factor URLs:" "Factor URLs:"
{ $subsection URL } { $subsection URL } ;
;
ABOUT: "db.types" ABOUT: "db.types"

View File

@ -126,11 +126,11 @@ ERROR: no-sql-type ;
HOOK: bind% db ( spec -- ) HOOK: bind% db ( spec -- )
HOOK: bind# db ( spec obj -- ) HOOK: bind# db ( spec obj -- )
: offset-of-slot ( string obj -- n ) : offset-of-slot ( string tuple -- n )
class superclasses [ "slots" word-prop ] map concat class superclasses [ "slots" word-prop ] map concat
slot-named offset>> ; slot-named offset>> ;
: get-slot-named ( name obj -- value ) : get-slot-named ( name tuple -- value )
tuck offset-of-slot slot ; tuck offset-of-slot slot ;
: set-slot-named ( value name obj -- ) : set-slot-named ( value name obj -- )