From 2dfb20bdb22b2ec2f38b964123d5657d833578a8 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Wed, 10 Oct 2012 13:18:25 +0000 Subject: [PATCH] applied a patch from RKITOVER (#80087) and added a fix to it --- dbdimp.c | 5 ++++- t/54_literal_txn.t | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 t/54_literal_txn.t diff --git a/dbdimp.c b/dbdimp.c index 2bc1480..359d077 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -39,6 +39,7 @@ imp_dbh_t *last_executed_dbh; /* needed by perl_tokenizer #define sqlite_trace(h,xxh,level,what) if ( DBIc_TRACE_LEVEL((imp_xxh_t*)xxh) >= level ) _sqlite_trace(aTHX_ __FILE__, __LINE__, h, (imp_xxh_t*)xxh, what) #define sqlite_exec(h,sql) _sqlite_exec(aTHX_ h, imp_dbh->db, sql) #define sqlite_open(dbname,db) _sqlite_open(aTHX_ dbh, dbname, db) +#define _isspace(c) (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\v' || c == '\f') static void _sqlite_trace(pTHX_ char *file, int line, SV *h, imp_xxh_t *imp_xxh, const char *what) @@ -741,6 +742,7 @@ 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++; if ((sql[0] == 'B' || sql[0] == 'b') && (sql[1] == 'E' || sql[1] == 'e') && (sql[2] == 'G' || sql[2] == 'g') && @@ -766,6 +768,7 @@ 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++; if (((sql[0] == 'C' || sql[0] == 'c') && (sql[1] == 'O' || sql[1] == 'o') && (sql[2] == 'M' || sql[2] == 'm') && @@ -787,7 +790,7 @@ sqlite_st_execute(SV *sth, imp_sth_t *imp_sth) int l = strlen(sql); bool is_savepoint = FALSE; for(i = 8; i < l; i++) { - if (sql[i] == ' ' || sql[i] == '\t') continue; + if (_isspace(sql[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 new file mode 100644 index 0000000..15e1920 --- /dev/null +++ b/t/54_literal_txn.t @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use t::lib::Test qw/connect_ok/; +use Test::More; + +my $dbh = connect_ok(); + +is $dbh->{AutoCommit}, 1, + 'AutoCommit=1 at connection'; + +$dbh->do('BEGIN TRANSACTION'); + +is $dbh->{AutoCommit}, '', + "AutoCommit='' after 'BEGIN TRANSACTION'"; + +$dbh->do("SELECT 1 FROM sqlite_master LIMIT 1"); + +$dbh->do("\nCOMMIT"); + +is $dbh->{AutoCommit}, 1, + 'AutoCommit=1 after "\nCOMMIT"'; + +done_testing;