From: Peter Rabbitson Date: Mon, 23 Jan 2012 09:32:45 +0000 (+0100) Subject: Correct SQLite quote-char X-Git-Tag: v0.11011~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f6e49d345306c610c9051b01790540e4de9e9292;p=dbsrgits%2FSQL-Translator.git Correct SQLite quote-char The original writer of d8cf2279 didn't do his/her homework, and used an incorrect quote character. Thic compounded with SQLite trying really hard to guess what one meant made the issue very hard to spot. http://www.sqlite.org/lang_keywords.html --- diff --git a/lib/SQL/Translator/Producer/SQLite.pm b/lib/SQL/Translator/Producer/SQLite.pm index 5ac49b8..645d014 100644 --- a/lib/SQL/Translator/Producer/SQLite.pm +++ b/lib/SQL/Translator/Producer/SQLite.pm @@ -23,7 +23,7 @@ use Data::Dumper; use SQL::Translator::Schema::Constants; use SQL::Translator::Utils qw(debug header_comment parse_dbms_version); use SQL::Translator::ProducerUtils; -my $util = SQL::Translator::ProducerUtils->new( quote_chars => q(') ); +my $util = SQL::Translator::ProducerUtils->new( quote_chars => q(") ); our ( $DEBUG, $WARN ); our $VERSION = '1.59'; diff --git a/t/30sqlt-new-diff-sqlite.t b/t/30sqlt-new-diff-sqlite.t index c6b4b92..d77e7b7 100644 --- a/t/30sqlt-new-diff-sqlite.t +++ b/t/30sqlt-new-diff-sqlite.t @@ -44,35 +44,35 @@ eq_or_diff($out, <<'## END OF DIFF', "Diff as expected"); BEGIN; -CREATE TABLE 'added' ( - 'id' int(11) +CREATE TABLE "added" ( + "id" int(11) ); -ALTER TABLE 'old_name' RENAME TO 'new_name'; +ALTER TABLE "old_name" RENAME TO "new_name"; -DROP INDEX 'FK5302D47D93FE702E'; +DROP INDEX "FK5302D47D93FE702E"; -DROP INDEX 'UC_age_name'; +DROP INDEX "UC_age_name"; -DROP INDEX 'u_name'; +DROP INDEX "u_name"; -- SQL::Translator::Producer::SQLite cant drop_field; -ALTER TABLE 'new_name' ADD COLUMN 'new_field' int; +ALTER TABLE "new_name" ADD COLUMN "new_field" int; -ALTER TABLE 'person' ADD COLUMN 'is_rock_star' tinyint(4) DEFAULT 1; +ALTER TABLE "person" ADD COLUMN "is_rock_star" tinyint(4) DEFAULT 1; -- SQL::Translator::Producer::SQLite cant alter_field; -- SQL::Translator::Producer::SQLite cant rename_field; -CREATE UNIQUE INDEX 'unique_name' ON 'person' ('name'); +CREATE UNIQUE INDEX "unique_name" ON "person" ("name"); -CREATE UNIQUE INDEX 'UC_person_id' ON 'person' ('person_id'); +CREATE UNIQUE INDEX "UC_person_id" ON "person" ("person_id"); -CREATE UNIQUE INDEX 'UC_age_name' ON 'person' ('age', 'name'); +CREATE UNIQUE INDEX "UC_age_name" ON "person" ("age", "name"); -DROP TABLE 'deleted'; +DROP TABLE "deleted"; COMMIT; @@ -91,71 +91,71 @@ eq_or_diff($out, <<'## END OF DIFF', "Diff as expected"); BEGIN; -CREATE TABLE 'added' ( - 'id' int(11) +CREATE TABLE "added" ( + "id" int(11) ); -CREATE TEMPORARY TABLE 'employee_temp_alter' ( - 'position' varchar(50) NOT NULL, - 'employee_id' int(11) NOT NULL, - PRIMARY KEY ('position', 'employee_id'), - FOREIGN KEY ('employee_id') REFERENCES 'person'('person_id') +CREATE TEMPORARY TABLE "employee_temp_alter" ( + "position" varchar(50) NOT NULL, + "employee_id" int(11) NOT NULL, + PRIMARY KEY ("position", "employee_id"), + FOREIGN KEY ("employee_id") REFERENCES "person"("person_id") ); -INSERT INTO 'employee_temp_alter' SELECT 'position', 'employee_id' FROM 'employee'; +INSERT INTO "employee_temp_alter" SELECT "position", "employee_id" FROM "employee"; -DROP TABLE 'employee'; +DROP TABLE "employee"; -CREATE TABLE 'employee' ( - 'position' varchar(50) NOT NULL, - 'employee_id' int(11) NOT NULL, - PRIMARY KEY ('position', 'employee_id'), - FOREIGN KEY ('employee_id') REFERENCES 'person'('person_id') +CREATE TABLE "employee" ( + "position" varchar(50) NOT NULL, + "employee_id" int(11) NOT NULL, + PRIMARY KEY ("position", "employee_id"), + FOREIGN KEY ("employee_id") REFERENCES "person"("person_id") ); -INSERT INTO 'employee' SELECT 'position', 'employee_id' FROM 'employee_temp_alter'; +INSERT INTO "employee" SELECT "position", "employee_id" FROM "employee_temp_alter"; -DROP TABLE 'employee_temp_alter'; +DROP TABLE "employee_temp_alter"; -ALTER TABLE 'old_name' RENAME TO 'new_name'; +ALTER TABLE "old_name" RENAME TO "new_name"; -ALTER TABLE 'new_name' ADD COLUMN 'new_field' int; +ALTER TABLE "new_name" ADD COLUMN "new_field" int; -CREATE TEMPORARY TABLE 'person_temp_alter' ( - 'person_id' INTEGER PRIMARY KEY NOT NULL, - 'name' varchar(20) NOT NULL, - 'age' int(11) DEFAULT 18, - 'weight' double(11,2), - 'iq' int(11) DEFAULT 0, - 'is_rock_star' tinyint(4) DEFAULT 1, - 'physical_description' text +CREATE TEMPORARY TABLE "person_temp_alter" ( + "person_id" INTEGER PRIMARY KEY NOT NULL, + "name" varchar(20) NOT NULL, + "age" int(11) DEFAULT 18, + "weight" double(11,2), + "iq" int(11) DEFAULT 0, + "is_rock_star" tinyint(4) DEFAULT 1, + "physical_description" text ); -INSERT INTO 'person_temp_alter' SELECT 'person_id', 'name', 'age', 'weight', 'iq', 'is_rock_star', 'physical_description' FROM 'person'; +INSERT INTO "person_temp_alter" SELECT "person_id", "name", "age", "weight", "iq", "is_rock_star", "physical_description" FROM "person"; -DROP TABLE 'person'; +DROP TABLE "person"; -CREATE TABLE 'person' ( - 'person_id' INTEGER PRIMARY KEY NOT NULL, - 'name' varchar(20) NOT NULL, - 'age' int(11) DEFAULT 18, - 'weight' double(11,2), - 'iq' int(11) DEFAULT 0, - 'is_rock_star' tinyint(4) DEFAULT 1, - 'physical_description' text +CREATE TABLE "person" ( + "person_id" INTEGER PRIMARY KEY NOT NULL, + "name" varchar(20) NOT NULL, + "age" int(11) DEFAULT 18, + "weight" double(11,2), + "iq" int(11) DEFAULT 0, + "is_rock_star" tinyint(4) DEFAULT 1, + "physical_description" text ); -CREATE UNIQUE INDEX 'unique_name02' ON 'person' ('name'); +CREATE UNIQUE INDEX "unique_name02" ON "person" ("name"); -CREATE UNIQUE INDEX 'UC_person_id02' ON 'person' ('person_id'); +CREATE UNIQUE INDEX "UC_person_id02" ON "person" ("person_id"); -CREATE UNIQUE INDEX 'UC_age_name02' ON 'person' ('age', 'name'); +CREATE UNIQUE INDEX "UC_age_name02" ON "person" ("age", "name"); -INSERT INTO 'person' SELECT 'person_id', 'name', 'age', 'weight', 'iq', 'is_rock_star', 'physical_description' FROM 'person_temp_alter'; +INSERT INTO "person" SELECT "person_id", "name", "age", "weight", "iq", "is_rock_star", "physical_description" FROM "person_temp_alter"; -DROP TABLE 'person_temp_alter'; +DROP TABLE "person_temp_alter"; -DROP TABLE 'deleted'; +DROP TABLE "deleted"; COMMIT; diff --git a/t/48xml-to-sqlite.t b/t/48xml-to-sqlite.t index c567bbc..8bccd28 100644 --- a/t/48xml-to-sqlite.t +++ b/t/48xml-to-sqlite.t @@ -36,51 +36,51 @@ my $sql = $sqlt->translate( eq_or_diff($sql, << "SQL"); BEGIN TRANSACTION; -DROP TABLE 'Basic'; - -CREATE TABLE 'Basic' ( - 'id' INTEGER PRIMARY KEY NOT NULL, - 'title' varchar(100) NOT NULL DEFAULT 'hello', - 'description' text DEFAULT '', - 'email' varchar(500), - 'explicitnulldef' varchar, - 'explicitemptystring' varchar DEFAULT '', +DROP TABLE "Basic"; + +CREATE TABLE "Basic" ( + "id" INTEGER PRIMARY KEY NOT NULL, + "title" varchar(100) NOT NULL DEFAULT 'hello', + "description" text DEFAULT '', + "email" varchar(500), + "explicitnulldef" varchar, + "explicitemptystring" varchar DEFAULT '', -- Hello emptytagdef - 'emptytagdef' varchar DEFAULT '', - 'another_id' int(10) DEFAULT 2, - 'timest' timestamp, - FOREIGN KEY ('another_id') REFERENCES 'Another'('id') + "emptytagdef" varchar DEFAULT '', + "another_id" int(10) DEFAULT 2, + "timest" timestamp, + FOREIGN KEY ("another_id") REFERENCES "Another"("id") ); -CREATE INDEX 'titleindex' ON 'Basic' ('title'); +CREATE INDEX "titleindex" ON "Basic" ("title"); -CREATE UNIQUE INDEX 'emailuniqueindex' ON 'Basic' ('email'); +CREATE UNIQUE INDEX "emailuniqueindex" ON "Basic" ("email"); -CREATE UNIQUE INDEX 'very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms' ON 'Basic' ('title'); +CREATE UNIQUE INDEX "very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms" ON "Basic" ("title"); -DROP TABLE 'Another'; +DROP TABLE "Another"; -CREATE TABLE 'Another' ( - 'id' INTEGER PRIMARY KEY NOT NULL, - 'num' numeric(10,2) +CREATE TABLE "Another" ( + "id" INTEGER PRIMARY KEY NOT NULL, + "num" numeric(10,2) ); -DROP VIEW IF EXISTS 'email_list'; +DROP VIEW IF EXISTS "email_list"; -CREATE VIEW 'email_list' AS +CREATE VIEW "email_list" AS SELECT email FROM Basic WHERE (email IS NOT NULL); -DROP TRIGGER IF EXISTS 'foo_trigger'; +DROP TRIGGER IF EXISTS "foo_trigger"; -CREATE TRIGGER 'foo_trigger' after insert on 'Basic' BEGIN update modified=timestamp(); END; +CREATE TRIGGER "foo_trigger" after insert on "Basic" BEGIN update modified=timestamp(); END; -DROP TRIGGER IF EXISTS 'bar_trigger_insert'; +DROP TRIGGER IF EXISTS "bar_trigger_insert"; -CREATE TRIGGER 'bar_trigger_insert' before insert on 'Basic' BEGIN update modified2=timestamp(); END; +CREATE TRIGGER "bar_trigger_insert" before insert on "Basic" BEGIN update modified2=timestamp(); END; -DROP TRIGGER IF EXISTS 'bar_trigger_update'; +DROP TRIGGER IF EXISTS "bar_trigger_update"; -CREATE TRIGGER 'bar_trigger_update' before update on 'Basic' BEGIN update modified2=timestamp(); END; +CREATE TRIGGER "bar_trigger_update" before update on "Basic" BEGIN update modified2=timestamp(); END; COMMIT; SQL @@ -95,37 +95,37 @@ my @sql = $sqlt->translate( eq_or_diff(\@sql, [ 'BEGIN TRANSACTION', - q, - q, + q, - q, - q, - q, - q, - q, + q, + q, + q, + q, - q, - q, + q, - q, - q, - q, - q, - q, - q, + q, + q, + q, + q, + q, + q, 'COMMIT', ], 'SQLite translate in list context matches'); diff --git a/t/56-sqlite-producer.t b/t/56-sqlite-producer.t index 752559d..7124a75 100644 --- a/t/56-sqlite-producer.t +++ b/t/56-sqlite-producer.t @@ -21,8 +21,8 @@ use SQL::Translator::Producer::SQLite; my $create_opts = { no_comments => 1 }; my $view1_sql1 = [ SQL::Translator::Producer::SQLite::create_view($view1, $create_opts) ]; - my $view_sql_replace = [ "CREATE TEMPORARY VIEW IF NOT EXISTS 'view_foo' AS - SELECT id, name FROM thing" ]; + my $view_sql_replace = [ 'CREATE TEMPORARY VIEW IF NOT EXISTS "view_foo" AS + SELECT id, name FROM thing' ]; is_deeply($view1_sql1, $view_sql_replace, 'correct "CREATE TEMPORARY VIEW" SQL'); @@ -31,8 +31,8 @@ use SQL::Translator::Producer::SQLite; sql => 'SELECT id, name FROM thing',); my $view1_sql2 = [ SQL::Translator::Producer::SQLite::create_view($view2, $create_opts) ]; - my $view_sql_noreplace = [ "CREATE VIEW 'view_foo' AS - SELECT id, name FROM thing" ]; + my $view_sql_noreplace = [ 'CREATE VIEW "view_foo" AS + SELECT id, name FROM thing' ]; is_deeply($view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL'); } { @@ -56,7 +56,7 @@ use SQL::Translator::Producer::SQLite; on_update => 'CASCADE', ); - my $expected = [ "FOREIGN KEY ('foreign_key') REFERENCES 'foo'('id') ON DELETE RESTRICT ON UPDATE CASCADE"]; + my $expected = [ 'FOREIGN KEY ("foreign_key") REFERENCES "foo"("id") ON DELETE RESTRICT ON UPDATE CASCADE']; my $result = [SQL::Translator::Producer::SQLite::create_foreignkey($constraint,$create_opts)]; is_deeply($result, $expected, 'correct "FOREIGN KEY"'); } diff --git a/t/57-class-dbi.t b/t/57-class-dbi.t index b2a5ecc..81daf2b 100644 --- a/t/57-class-dbi.t +++ b/t/57-class-dbi.t @@ -23,8 +23,8 @@ use SQL::Translator::Producer::SQLite; my $view1_sql1 = [ SQL::Translator::Producer::SQLite::create_view( $view1, $create_opts ) ]; - my $view_sql_replace = [ "CREATE TEMPORARY VIEW IF NOT EXISTS 'view_foo' AS - SELECT id, name FROM thing" ]; + my $view_sql_replace = [ 'CREATE TEMPORARY VIEW IF NOT EXISTS "view_foo" AS + SELECT id, name FROM thing' ]; is_deeply( $view1_sql1, $view_sql_replace, 'correct "CREATE TEMPORARY VIEW" SQL' ); my $view2 = SQL::Translator::Schema::View->new( @@ -35,7 +35,7 @@ use SQL::Translator::Producer::SQLite; my $view1_sql2 = [ SQL::Translator::Producer::SQLite::create_view( $view2, $create_opts ) ]; - my $view_sql_noreplace = [ "CREATE VIEW 'view_foo' AS - SELECT id, name FROM thing" ]; + my $view_sql_noreplace = [ 'CREATE VIEW "view_foo" AS + SELECT id, name FROM thing' ]; is_deeply( $view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL' ); }