From 8a418482dd8932b1a101129625a8cc6c3b6c3cc8 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Wed, 10 Oct 2012 15:17:20 +0000 Subject: [PATCH] should also ignore comments (#80087) --- dbdimp.c | 26 ++++++++++++++++++++++++-- t/54_literal_txn.t | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/dbdimp.c b/dbdimp.c index 359d077..7b98a02 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -742,7 +742,16 @@ sqlite_st_execute(SV *sth, imp_sth_t *imp_sth) if (sqlite3_get_autocommit(imp_dbh->db)) { /* COMPAT: sqlite3_sql is only available for 3006000 or newer */ const char *sql = sqlite3_sql(imp_sth->stmt); - while ( _isspace(sql[0]) ) sql++; + while ( _isspace(sql[0]) || (sql[0] == '-' && sql[1] == '-')) { + if ( _isspace(sql[0]) ) { + while ( _isspace(sql[0]) ) sql++; + continue; + } + else if (sql[0] == '-') { + while ( sql[0] != 0 && sql[0] != '\n' ) sql++; + continue; + } + } if ((sql[0] == 'B' || sql[0] == 'b') && (sql[1] == 'E' || sql[1] == 'e') && (sql[2] == 'G' || sql[2] == 'g') && @@ -768,7 +777,16 @@ sqlite_st_execute(SV *sth, imp_sth_t *imp_sth) else if (DBIc_is(imp_dbh, DBIcf_BegunWork)) { /* COMPAT: sqlite3_sql is only available for 3006000 or newer */ const char *sql = sqlite3_sql(imp_sth->stmt); - while ( _isspace(sql[0]) ) sql++; + while ( _isspace(sql[0]) || (sql[0] == '-' && sql[1] == '-')) { + if ( _isspace(sql[0]) ) { + while ( _isspace(sql[0]) ) sql++; + continue; + } + else if (sql[0] == '-') { + while ( sql[0] != 0 && sql[0] != '\n' ) sql++; + continue; + } + } if (((sql[0] == 'C' || sql[0] == 'c') && (sql[1] == 'O' || sql[1] == 'o') && (sql[2] == 'M' || sql[2] == 'm') && @@ -791,6 +809,10 @@ sqlite_st_execute(SV *sth, imp_sth_t *imp_sth) bool is_savepoint = FALSE; for(i = 8; i < l; i++) { if (_isspace(sql[i])) continue; + if (sql[i] == '-' && sql[i+1] == '-') { + while (sql[i] != 0 && sql[i] != '\n') i++; + continue; + } if (sql[i] == 'T' || sql[i] == 't') { if ((sql[i+0] == 'T' || sql[i+0] == 't') && (sql[i+1] == 'R' || sql[i+1] == 'r') && diff --git a/t/54_literal_txn.t b/t/54_literal_txn.t index 15e1920..dc81755 100644 --- a/t/54_literal_txn.t +++ b/t/54_literal_txn.t @@ -14,7 +14,7 @@ my $dbh = connect_ok(); is $dbh->{AutoCommit}, 1, 'AutoCommit=1 at connection'; -$dbh->do('BEGIN TRANSACTION'); +$dbh->do("\n-- my DDL file\n-- some comment\nBEGIN TRANSACTION"); is $dbh->{AutoCommit}, '', "AutoCommit='' after 'BEGIN TRANSACTION'";