From: Dagfinn Ilmari Mannsåker Date: Mon, 14 Jul 2014 20:59:55 +0000 (+0100) Subject: Test escaping quote characters in identifiers X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b25af2a8cd075015695e74ef077afd991442f615;p=dbsrgits%2FDBIx-Class.git Test escaping quote characters in identifiers This requires SQLA master (46be431) and SQLT people/ilmari/quoting-fixes Also add accessor for the new SQLA escape_char attribute. --- diff --git a/lib/DBIx/Class/SQLMaker.pm b/lib/DBIx/Class/SQLMaker.pm index 5b5181f..20677e8 100644 --- a/lib/DBIx/Class/SQLMaker.pm +++ b/lib/DBIx/Class/SQLMaker.pm @@ -42,7 +42,7 @@ use Sub::Name 'subname'; use DBIx::Class::Carp; use namespace::clean; -__PACKAGE__->mk_group_accessors (simple => qw/quote_char name_sep limit_dialect/); +__PACKAGE__->mk_group_accessors (simple => qw/quote_char escape_char name_sep limit_dialect/); # for when I need a normalized l/r pair sub _quote_chars { diff --git a/t/admin/02ddl.t b/t/admin/02ddl.t index d17d677..bcdb30b 100644 --- a/t/admin/02ddl.t +++ b/t/admin/02ddl.t @@ -47,7 +47,7 @@ my $admin = DBIx::Class::Admin->new( ); isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object'); lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql'; -lives_ok { $admin->create('SQLite'); } 'Can Create SQLite sql'; +lives_ok { $admin->create('SQLite', {quote_identifiers=>1}); } 'Can Create SQLite sql'; lives_ok { local $SIG{__WARN__} = sigwarn_silencer( qr/no such table.+DROP TABLE/s ); $admin->deploy() diff --git a/t/lib/DBICTest/Schema.pm b/t/lib/DBICTest/Schema.pm index 52906c7..9b11e21 100644 --- a/t/lib/DBICTest/Schema.pm +++ b/t/lib/DBICTest/Schema.pm @@ -53,7 +53,7 @@ __PACKAGE__->load_classes(qw/ ), qw/SelfRefAlias TreeLike TwoKeyTreeLike Event EventTZ NoPrimaryKey/, qw/Collection CollectionObject TypedObject Owners BooksInLibrary/, - qw/ForceForeign Encoded/, + qw/ForceForeign Encoded Quotes/, ); sub sqlt_deploy_hook { diff --git a/t/lib/DBICTest/Schema/Quotes.pm b/t/lib/DBICTest/Schema/Quotes.pm new file mode 100644 index 0000000..a6fe246 --- /dev/null +++ b/t/lib/DBICTest/Schema/Quotes.pm @@ -0,0 +1,20 @@ +package # hide from PAUSE + DBICTest::Schema::Quotes; + +use warnings; +use strict; + +use base 'DBICTest::BaseResult'; + +# Include all the common quote characters +__PACKAGE__->table('`with` [some] "quotes"'); + +__PACKAGE__->add_columns( + '`has` [more] "quotes"' => { + data_type => 'integer', + is_auto_increment => 1, + accessor => 'has_more_quotes', + }, +); + +1; diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index 64ddc33..6ae6b02 100644 --- a/t/lib/sqlite.sql +++ b/t/lib/sqlite.sql @@ -1,3 +1,7 @@ +CREATE TABLE "`with` [some] ""quotes""" ( + "`has` [more] ""quotes""" integer NOT NULL +); + CREATE TABLE "artist" ( "artistid" INTEGER PRIMARY KEY NOT NULL, "name" varchar(100), diff --git a/t/sqlmaker/quotes.t b/t/sqlmaker/quotes.t index 4a5357b..e4c6dbd 100644 --- a/t/sqlmaker/quotes.t +++ b/t/sqlmaker/quotes.t @@ -32,6 +32,13 @@ is_same_sql_bind( 'got correct SQL for count query with bracket quoting' ); +is_same_sql_bind( + $schema->resultset('Quotes')->search({})->as_query, + '(SELECT [me].[`has` [more]] "quotes"] FROM [`with` [some]] "quotes"] [me])', + [], + 'got correct escaped quotes with bracket quoting' +); + $schema->storage->sql_maker->quote_char('`'); $schema->storage->sql_maker->name_sep('.'); @@ -42,6 +49,13 @@ is_same_sql_bind ( 'got correct SQL for count query with mysql quoting' ); +is_same_sql_bind( + $schema->resultset('Quotes')->search({})->as_query, + '(SELECT `me`.```has`` [more] "quotes"` FROM ```with`` [some] "quotes"` `me`)', + [], + 'got correct escaped quotes with mysql quoting' +); + # !!! talk to ribasushi *explicitly* before modfying these tests !!! { is_same_sql_bind( diff --git a/t/storage/quote_names.t b/t/storage/quote_names.t index 6492f25..20eebac 100644 --- a/t/storage/quote_names.t +++ b/t/storage/quote_names.t @@ -130,9 +130,9 @@ for my $db (sort { # if something was produced - it better be quoted if ( my $ddl = try { $schema->deployment_statements } ) { - my $quoted_artist = $schema->storage->sql_maker->_quote('artist'); + my $quoted_table = $schema->storage->sql_maker->_quote($schema->source('Quotes')->from); - like ($ddl, qr/^CREATE\s+TABLE\s+\Q$quoted_artist/msi, "$db DDL contains expected quoted table name"); + like ($ddl, qr/^CREATE\s+TABLE\s+\Q$quoted_table/msi, "$db DDL contains expected quoted table name"); } }