forked from sparklemotion/sqlite3-ruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
centralizing exception handling, removing dead code
- Loading branch information
1 parent
c8e34e8
commit da74b8e
Showing
9 changed files
with
119 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include <sqlite3_ruby.h> | ||
|
||
void rb_sqlite3_raise(sqlite3 * db, int status) | ||
{ | ||
VALUE klass = Qnil; | ||
|
||
switch(status) { | ||
case SQLITE_OK: | ||
return; | ||
break; | ||
case SQLITE_ERROR: | ||
klass = rb_path2class("SQLite3::SQLException"); | ||
break; | ||
case SQLITE_INTERNAL: | ||
klass = rb_path2class("SQLite3::InternalException"); | ||
break; | ||
case SQLITE_PERM: | ||
klass = rb_path2class("SQLite3::PermissionException"); | ||
break; | ||
case SQLITE_ABORT: | ||
klass = rb_path2class("SQLite3::AbortException"); | ||
break; | ||
case SQLITE_BUSY: | ||
klass = rb_path2class("SQLite3::BusyException"); | ||
break; | ||
case SQLITE_LOCKED: | ||
klass = rb_path2class("SQLite3::LockedException"); | ||
break; | ||
case SQLITE_NOMEM: | ||
klass = rb_path2class("SQLite3::MemoryException"); | ||
break; | ||
case SQLITE_READONLY: | ||
klass = rb_path2class("SQLite3::ReadOnlyException"); | ||
break; | ||
case SQLITE_INTERRUPT: | ||
klass = rb_path2class("SQLite3::InterruptException"); | ||
break; | ||
case SQLITE_IOERR: | ||
klass = rb_path2class("SQLite3::IOException"); | ||
break; | ||
case SQLITE_CORRUPT: | ||
klass = rb_path2class("SQLite3::CorruptException"); | ||
break; | ||
case SQLITE_NOTFOUND: | ||
klass = rb_path2class("SQLite3::NotFoundException"); | ||
break; | ||
case SQLITE_FULL: | ||
klass = rb_path2class("SQLite3::FullException"); | ||
break; | ||
case SQLITE_CANTOPEN: | ||
klass = rb_path2class("SQLite3::CantOpenException"); | ||
break; | ||
case SQLITE_PROTOCOL: | ||
klass = rb_path2class("SQLite3::ProtocolException"); | ||
break; | ||
case SQLITE_EMPTY: | ||
klass = rb_path2class("SQLite3::EmptyException"); | ||
break; | ||
case SQLITE_SCHEMA: | ||
klass = rb_path2class("SQLite3::SchemaChangedException"); | ||
break; | ||
case SQLITE_TOOBIG: | ||
klass = rb_path2class("SQLite3::TooBigException"); | ||
break; | ||
case SQLITE_CONSTRAINT: | ||
klass = rb_path2class("SQLite3::ConstraintException"); | ||
break; | ||
case SQLITE_MISMATCH: | ||
klass = rb_path2class("SQLite3::MismatchException"); | ||
break; | ||
case SQLITE_MISUSE: | ||
klass = rb_path2class("SQLite3::MisuseException"); | ||
break; | ||
case SQLITE_NOLFS: | ||
klass = rb_path2class("SQLite3::UnsupportedException"); | ||
break; | ||
case SQLITE_AUTH: | ||
klass = rb_path2class("SQLite3::AuthorizationException"); | ||
break; | ||
case SQLITE_FORMAT: | ||
klass = rb_path2class("SQLite3::FormatException"); | ||
break; | ||
case SQLITE_RANGE: | ||
klass = rb_path2class("SQLite3::RangeException"); | ||
break; | ||
case SQLITE_NOTADB: | ||
klass = rb_path2class("SQLite3::NotADatabaseException"); | ||
break; | ||
default: | ||
klass = rb_eRuntimeError; | ||
} | ||
|
||
rb_raise(klass, "%s", sqlite3_errmsg(db)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef SQLITE3_EXCEPTION_RUBY | ||
#define SQLITE3_EXCEPTION_RUBY | ||
|
||
#define CHECK(_db, _status) rb_sqlite3_raise(_db, _status); | ||
|
||
void rb_sqlite3_raise(sqlite3 * db, int status); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ extern VALUE mSqlite3; | |
|
||
#include <database.h> | ||
#include <statement.h> | ||
#include <exception.h> | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters