]> gitweb.factorcode.org Git - factor.git/commitdiff
rename db-table to db-table-name, use db-table-name instead of class name in creating...
authorDoug Coleman <doug.coleman@gmail.com>
Thu, 12 Feb 2009 23:29:31 +0000 (17:29 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Thu, 12 Feb 2009 23:29:31 +0000 (17:29 -0600)
basis/db/queries/queries.factor
basis/db/sqlite/sqlite.factor
basis/db/types/types.factor

index c714f43687d8ad7620f2a1f260bde4679f2508ab..2730340bfc11c376936e7b19da3989336c47886f 100755 (executable)
@@ -44,11 +44,11 @@ M: retryable execute-statement* ( statement type -- )
     ] bi attempt-all drop ;
 
 : sql-props ( class -- columns table )
-    [ db-columns ] [ db-table ] bi ;
+    [ db-columns ] [ db-table-name ] bi ;
 
 : query-make ( class quot -- statements )
     #! query, input, outputs, secondary queries
-    over db-table "table" set
+    over db-table-name "table-name" set
     [ sql-props ] dip
     [ 0 sql-counter rot with-variable ] curry
     { "" { } { } { } } nmake
index 9b05cf9825d7397312c9d7b89c62557bfa996eca..d006145ea83caad2080978e17d9d2b3e89f998a8 100755 (executable)
@@ -225,11 +225,11 @@ M: sqlite-db-connection persistent-table ( -- assoc )
 : insert-trigger ( -- string )
     [
     <"
-        CREATE TRIGGER fki_${table}_${foreign-table}_id
-        BEFORE INSERT ON ${table}
+        CREATE TRIGGER fki_${table-name}_${foreign-table-name}_id
+        BEFORE INSERT ON ${table-name}
         FOR EACH ROW BEGIN
-            SELECT RAISE(ROLLBACK, 'insert on table "${table}" violates foreign key constraint "fk_${foreign-table}_id"')
-            WHERE  (SELECT ${foreign-table-id} FROM ${foreign-table} WHERE ${foreign-table-id} = NEW.${table-id}) IS NULL;
+            SELECT RAISE(ROLLBACK, 'insert on table "${table-name}" violates foreign key constraint "fk_${foreign-table-name}_id"')
+            WHERE  (SELECT ${foreign-table-id} FROM ${foreign-table-name} WHERE ${foreign-table-id} = NEW.${table-id}) IS NULL;
         END;
     "> interpolate
     ] with-string-writer ;
@@ -237,12 +237,12 @@ M: sqlite-db-connection persistent-table ( -- assoc )
 : insert-trigger-not-null ( -- string )
     [
     <"
-        CREATE TRIGGER fki_${table}_${foreign-table}_id
-        BEFORE INSERT ON ${table}
+        CREATE TRIGGER fki_${table-name}_${foreign-table-name}_id
+        BEFORE INSERT ON ${table-name}
         FOR EACH ROW BEGIN
-            SELECT RAISE(ROLLBACK, 'insert on table "${table}" violates foreign key constraint "fk_${foreign-table}_id"')
+            SELECT RAISE(ROLLBACK, 'insert on table "${table-name}" violates foreign key constraint "fk_${foreign-table-name}_id"')
             WHERE NEW.${foreign-table-id} IS NOT NULL
-                AND (SELECT ${foreign-table-id} FROM ${foreign-table} WHERE ${foreign-table-id} = NEW.${table-id}) IS NULL;
+                AND (SELECT ${foreign-table-id} FROM ${foreign-table-name} WHERE ${foreign-table-id} = NEW.${table-id}) IS NULL;
         END;
     "> interpolate
     ] with-string-writer ;
@@ -250,11 +250,11 @@ M: sqlite-db-connection persistent-table ( -- assoc )
 : update-trigger ( -- string )
     [
     <"
-        CREATE TRIGGER fku_${table}_${foreign-table}_id
-        BEFORE UPDATE ON ${table}
+        CREATE TRIGGER fku_${table-name}_${foreign-table-name}_id
+        BEFORE UPDATE ON ${table-name}
         FOR EACH ROW BEGIN
-            SELECT RAISE(ROLLBACK, 'update on table "${table}" violates foreign key constraint "fk_${foreign-table}_id"')
-            WHERE  (SELECT ${foreign-table-id} FROM ${foreign-table} WHERE ${foreign-table-id} = NEW.${table-id}) IS NULL;
+            SELECT RAISE(ROLLBACK, 'update on table "${table-name}" violates foreign key constraint "fk_${foreign-table-name}_id"')
+            WHERE  (SELECT ${foreign-table-id} FROM ${foreign-table-name} WHERE ${foreign-table-id} = NEW.${table-id}) IS NULL;
         END;
     "> interpolate
     ] with-string-writer ;
@@ -262,12 +262,12 @@ M: sqlite-db-connection persistent-table ( -- assoc )
 : update-trigger-not-null ( -- string )
     [
     <"
-        CREATE TRIGGER fku_${table}_${foreign-table}_id
-        BEFORE UPDATE ON ${table}
+        CREATE TRIGGER fku_${table-name}_${foreign-table-name}_id
+        BEFORE UPDATE ON ${table-name}
         FOR EACH ROW BEGIN
-            SELECT RAISE(ROLLBACK, 'update on table "${table}" violates foreign key constraint "fk_${foreign-table}_id"')
+            SELECT RAISE(ROLLBACK, 'update on table "${table-name}" violates foreign key constraint "fk_${foreign-table-name}_id"')
             WHERE NEW.${foreign-table-id} IS NOT NULL
-                AND (SELECT ${foreign-table-id} FROM ${foreign-table} WHERE ${foreign-table-id} = NEW.${table-id}) IS NULL;
+                AND (SELECT ${foreign-table-id} FROM ${foreign-table-name} WHERE ${foreign-table-id} = NEW.${table-id}) IS NULL;
         END;
     "> interpolate
     ] with-string-writer ;
@@ -275,11 +275,11 @@ M: sqlite-db-connection persistent-table ( -- assoc )
 : delete-trigger-restrict ( -- string )
     [
     <"
-        CREATE TRIGGER fkd_${table}_${foreign-table}_id
-        BEFORE DELETE ON ${foreign-table}
+        CREATE TRIGGER fkd_${table-name}_${foreign-table-name}_id
+        BEFORE DELETE ON ${foreign-table-name}
         FOR EACH ROW BEGIN
-            SELECT RAISE(ROLLBACK, 'delete on table "${foreign-table}" violates foreign key constraint "fk_${foreign-table}_id"')
-            WHERE  (SELECT ${foreign-table-id} FROM ${foreign-table} WHERE ${foreign-table-id} = OLD.${foreign-table-id}) IS NOT NULL;
+            SELECT RAISE(ROLLBACK, 'delete on table "${foreign-table-name}" violates foreign key constraint "fk_${foreign-table-name}_id"')
+            WHERE  (SELECT ${foreign-table-id} FROM ${foreign-table-name} WHERE ${foreign-table-id} = OLD.${foreign-table-id}) IS NOT NULL;
         END;
     "> interpolate
     ] with-string-writer ;
@@ -287,10 +287,10 @@ M: sqlite-db-connection persistent-table ( -- assoc )
 : delete-trigger-cascade ( -- string )
     [
     <"
-        CREATE TRIGGER fkd_${table}_${foreign-table}_id
-        BEFORE DELETE ON ${foreign-table}
+        CREATE TRIGGER fkd_${table-name}_${foreign-table-name}_id
+        BEFORE DELETE ON ${foreign-table-name}
         FOR EACH ROW BEGIN
-            DELETE from ${table} WHERE ${table-id} = OLD.${foreign-table-id};
+            DELETE from ${table-name} WHERE ${table-id} = OLD.${foreign-table-id};
         END;
     "> interpolate
     ] with-string-writer ;
@@ -323,7 +323,7 @@ M: sqlite-db-connection compound ( string seq -- new-string )
         { "default" [ first number>string " " glue ] }
         { "references" [
             [ >reference-string ] keep
-            first2 [ "foreign-table" set ]
+            first2 [ db-table-name "foreign-table-name" set ]
             [ "foreign-table-id" set ] bi*
             create-sqlite-triggers
         ] }
index 51e4b42bdc46f4756170932e5279ddecede7d7a2..e39a5977eff9d14192e337dd588de85521adff68 100755 (executable)
@@ -49,7 +49,7 @@ ERROR: no-slot ;
 
 ERROR: not-persistent class ;
 
-: db-table ( class -- object )
+: db-table-name ( class -- object )
     dup "db-table" word-prop [ ] [ not-persistent ] ?if ;
 
 : db-columns ( class -- object )
@@ -165,7 +165,7 @@ ERROR: no-column column ;
 
 : >reference-string ( string pair -- string )
     first2
-    [ [ db-table " " glue ] [ db-columns ] bi ] dip
+    [ [ db-table-name " " glue ] [ db-columns ] bi ] dip
     swap [ column-name>> = ] with find nip
     [ no-column ] unless*
     column-name>> "(" ")" surround append ;