Permalink
Browse files

Merge branch 'master' of jeremy@hinegardner.org:/var/git/amalgalite

  • Loading branch information...
2 parents b2edf7e + 39d2fb9 commit e4eeda66bbf77e71413070ee5ef0a5a56fd17294 @copiousfreetime committed Mar 3, 2009
View
@@ -7,6 +7,7 @@
=== Bug Fixes
+* fix issues with the wrong error message appearing in statement closing
* incorrectly raise an exception if a transaction is started when rescuing an
exception [reported by James Edwared Gray II]
@@ -594,18 +594,18 @@ int amalgalite_xProgress( void *pArg )
VALUE am_sqlite3_database_progress_handler( VALUE self, VALUE op_count, VALUE handler )
{
am_sqlite3 *am_db;
- int op_codes = FIX2INT( op_count );
Data_Get_Struct(self, am_sqlite3, am_db);
/* Removing a progress handler, remove it from sqlite and then remove it
* from the garbage collector if it existed */
if ( Qnil == handler ) {
- sqlite3_progress_handler( am_db->db, 0, NULL, (void*)NULL );
+ sqlite3_progress_handler( am_db->db, -1, NULL, (void*)NULL );
if ( Qnil != am_db->progress_handler_obj ) {
rb_gc_unregister_address( &(am_db->progress_handler_obj) );
}
} else {
+ int op_codes = FIX2INT( op_count );
/* installing a progress handler
* - register it with sqlite
* - keep a reference for ourselves with our database handle
@@ -530,18 +530,27 @@ VALUE am_sqlite3_statement_sql(VALUE self)
* stmt.close -> nil
*
* Closes the statement. If there is a problem closing the statement then an
- * error is raised.
+ * error is raised. Closing a statement when there is an existing error is
+ * perfectly fine.
+ *
*/
VALUE am_sqlite3_statement_close( VALUE self )
{
am_sqlite3_stmt *am_stmt;
- int rc;
+ int rc, existing_errcode;
Data_Get_Struct(self, am_sqlite3_stmt, am_stmt);
+
+ /* check the current error code to see if one exists, we could be
+ * closing a statement that has an error, and in that case we do not want to
+ * raise an additional error, we want to let the existing error stand
+ */
+ existing_errcode = sqlite3_errcode( sqlite3_db_handle( am_stmt->stmt ) );
rc = sqlite3_finalize( am_stmt->stmt );
- if ( SQLITE_OK != rc ) {
- rb_raise(eAS_Error, "Failure to close statment : [SQLITE_ERROR %d] : %s\n",
+
+ if ( (SQLITE_OK != rc) && (rc != existing_errcode) ) {
+ rb_raise(eAS_Error, "Failure to close statement : [SQLITE_ERROR %d] : %s\n",
rc, sqlite3_errmsg( sqlite3_db_handle( am_stmt->stmt) ));
}
@@ -575,6 +584,8 @@ VALUE am_sqlite3_statement_alloc(VALUE klass)
am_sqlite3_stmt *wrapper = ALLOC(am_sqlite3_stmt);
VALUE obj = (VALUE)NULL;
+ wrapper->remaining_sql = Qnil;
+
obj = Data_Wrap_Struct(klass, NULL, am_sqlite3_statement_free, wrapper);
return obj;
}
@@ -165,6 +165,7 @@ def open?
def close
if open? then
@api.close
+ @open = false
end
end
@@ -35,6 +35,14 @@ def initialize( db, sql )
@blobs_to_write = []
@rowid_index = nil
@result_meta = nil
+ @open = true
+ end
+
+ ##
+ # is the statement open for business
+ #
+ def open?
+ @open
end
##
@@ -288,8 +296,10 @@ def next_row
row = nil
write_blobs
else
- raise Amalgalite::SQLite3::Error,
- "SQLITE ERROR #{rc} (#{Amalgalite::SQLite3::Constants::ResultCode.name_from_value( rc )}) : #{@db.api.last_error_message}"
+ self.close # must close so that the error message is guaranteed to be pushed into the database handler
+ # and we can can call last_error_message on it
+ msg = "SQLITE ERROR #{rc} (#{Amalgalite::SQLite3::Constants::ResultCode.name_from_value( rc )}) : #{@db.api.last_error_message}"
+ raise Amalgalite::SQLite3::Error, msg
end
return row
end
@@ -396,7 +406,10 @@ def sql
# has been closed.
#
def close
- @stmt_api.close
+ if open?
+ @stmt_api.close
+ @open = false
+ end
end
end
end
@@ -1,7 +1,8 @@
require 'rubygems'
require 'spec'
-$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
+require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
+
require 'amalgalite'
require 'amalgalite/database'
@@ -1,7 +1,8 @@
require 'rubygems'
require 'spec'
-$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
+require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper.rb' ) )
+
require 'amalgalite'
require 'amalgalite/database'
@@ -1,7 +1,7 @@
require 'rubygems'
require 'spec'
+require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
-$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
require 'amalgalite'
require 'amalgalite/database'
class PH < ::Amalgalite::ProgressHandler
@@ -82,6 +82,8 @@ def query_thread( db )
qt.join
ph.call_count.should eql(25)
qt[:exception].should be_instance_of( ::Amalgalite::SQLite3::Error )
+ @iso_db.api.last_error_code.should == 9
+ @iso_db.api.last_error_message.should =~ /interrupted/
qt[:exception].message.should =~ /interrupted/
end
View
@@ -2,6 +2,8 @@
require 'spec'
$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
+$: << File.expand_path(File.join(File.dirname(__FILE__),"..","ext"))
+
require 'amalgalite'
class SpecInfo
@@ -1,7 +1,8 @@
require 'rubygems'
require 'spec'
-$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
+require File.expand_path( File.join( File.dirname( __FILE__ ), "spec_helper.rb" ) )
+
require 'amalgalite'
describe Amalgalite::Statement do
View
@@ -62,7 +62,7 @@
mode "spec"
files Configuration.for("packaging").files.test
options %w[ --format progress --color ]
- ruby_opts %w[ -w ]
+ ruby_opts %w[ ]
}
#-----------------------------------------------------------------------
@@ -72,7 +72,7 @@
output_dir "coverage"
libs %w[ lib ]
rcov_opts %w[ --html ]
- ruby_opts %w[ -w ]
+ ruby_opts %w[ ]
test_files Configuration.for('packaging').files.test
}
#
View
@@ -18,7 +18,7 @@ if spec_config = Configuration.for_if_exist?("test") then
Amalgalite::Paths.root_dir ]
r.spec_files = spec_config.files
r.spec_opts = spec_config.options
- r.warning = true
+ #r.warning = true
if rcov_config = Configuration.for_if_exist?('rcov') then
r.rcov = true

0 comments on commit e4eeda6

Please sign in to comment.