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';
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;
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;
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
eq_or_diff(\@sql,
[
'BEGIN TRANSACTION',
- q<DROP TABLE 'Basic'>,
- q<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 '',
+ q<DROP TABLE "Basic">,
+ q<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")
)>,
- q<CREATE INDEX 'titleindex' ON 'Basic' ('title')>,
- q<CREATE UNIQUE INDEX 'emailuniqueindex' ON 'Basic' ('email')>,
- q<CREATE UNIQUE INDEX 'very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms' ON 'Basic' ('title')>,
- q<DROP TABLE 'Another'>,
- q<CREATE TABLE 'Another' (
- 'id' INTEGER PRIMARY KEY NOT NULL,
- 'num' numeric(10,2)
+ q<CREATE INDEX "titleindex" ON "Basic" ("title")>,
+ q<CREATE UNIQUE INDEX "emailuniqueindex" ON "Basic" ("email")>,
+ q<CREATE UNIQUE INDEX "very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms" ON "Basic" ("title")>,
+ q<DROP TABLE "Another">,
+ q<CREATE TABLE "Another" (
+ "id" INTEGER PRIMARY KEY NOT NULL,
+ "num" numeric(10,2)
)>,
- q<DROP VIEW IF EXISTS 'email_list'>,
- q<CREATE VIEW 'email_list' AS
+ q<DROP VIEW IF EXISTS "email_list">,
+ q<CREATE VIEW "email_list" AS
SELECT email FROM Basic WHERE (email IS NOT NULL)>,
- q<DROP TRIGGER IF EXISTS 'foo_trigger'>,
- q<CREATE TRIGGER 'foo_trigger' after insert on 'Basic' BEGIN update modified=timestamp(); END>,
- q<DROP TRIGGER IF EXISTS 'bar_trigger_insert'>,
- q<CREATE TRIGGER 'bar_trigger_insert' before insert on 'Basic' BEGIN update modified2=timestamp(); END>,
- q<DROP TRIGGER IF EXISTS 'bar_trigger_update'>,
- q<CREATE TRIGGER 'bar_trigger_update' before update on 'Basic' BEGIN update modified2=timestamp(); END>,
+ q<DROP TRIGGER IF EXISTS "foo_trigger">,
+ q<CREATE TRIGGER "foo_trigger" after insert on "Basic" BEGIN update modified=timestamp(); END>,
+ q<DROP TRIGGER IF EXISTS "bar_trigger_insert">,
+ q<CREATE TRIGGER "bar_trigger_insert" before insert on "Basic" BEGIN update modified2=timestamp(); END>,
+ q<DROP TRIGGER IF EXISTS "bar_trigger_update">,
+ q<CREATE TRIGGER "bar_trigger_update" before update on "Basic" BEGIN update modified2=timestamp(); END>,
'COMMIT',
], 'SQLite translate in list context matches');
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');
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');
}
{
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"');
}
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(
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' );
}