diff --git a/ext/duckdb/prepared_statement.c b/ext/duckdb/prepared_statement.c index 223df61..ccf4dfb 100644 --- a/ext/duckdb/prepared_statement.c +++ b/ext/duckdb/prepared_statement.c @@ -72,7 +72,8 @@ VALUE rbduckdb_prepared_statement_new(duckdb_connection con, duckdb_extracted_st TypedData_Get_Struct(obj, rubyDuckDBPreparedStatement, &prepared_statement_data_type, ctx); if (duckdb_prepare_extracted_statement(con, extracted_statements, index, &(ctx->prepared_statement)) == DuckDBError) { - rb_raise(eDuckDBError, "Failed to create DuckDB::PreparedStatement object."); + const char *error = duckdb_prepare_error(ctx->prepared_statement); + rb_raise(eDuckDBError, "%s", error ? error : "Failed to create DuckDB::PreparedStatement object."); } return obj; } @@ -90,7 +91,7 @@ static VALUE duckdb_prepared_statement_initialize(VALUE self, VALUE con, VALUE q if (duckdb_prepare(ctxcon->con, StringValuePtr(query), &(ctx->prepared_statement)) == DuckDBError) { const char *error = duckdb_prepare_error(ctx->prepared_statement); - rb_raise(eDuckDBError, "%s", error); + rb_raise(eDuckDBError, "%s", error ? error : "Failed to prepare statement(Database connection closed?)."); } return self; } diff --git a/test/duckdb_test/database_test.rb b/test/duckdb_test/database_test.rb index 2de4799..c1ae3c4 100644 --- a/test/duckdb_test/database_test.rb +++ b/test/duckdb_test/database_test.rb @@ -88,7 +88,7 @@ def test_close con.query('SELECT * from DUMMY') end - assert_equal('Failed to create DuckDB::PreparedStatement object.', exception.message) + assert_match(/DUMMY does not exist/, exception.message) end private