amalgalite 0.7.5-x86-mswin32-60 → 0.7.6-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +12 -0
- data/ext/amalgalite3_database.c +2 -2
- data/ext/amalgalite3_statement.c +15 -4
- data/ext/sqlite3.c +4430 -2733
- data/ext/sqlite3.h +226 -24
- data/ext/test_error.c +22 -37
- data/lib/amalgalite/database.rb +3 -1
- data/lib/amalgalite/statement.rb +16 -3
- data/lib/amalgalite/version.rb +1 -1
- data/lib/amalgalite3.so +0 -0
- data/spec/aggregate_spec.rb +2 -1
- data/spec/busy_handler.rb +2 -1
- data/spec/database_spec.rb +30 -0
- data/spec/progress_handler_spec.rb +3 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/sqlite3/version_spec.rb +2 -2
- data/spec/statement_spec.rb +2 -1
- data/tasks/config.rb +2 -2
- data/tasks/rspec.rake +1 -1
- metadata +2 -2
data/ext/sqlite3.h
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
** the version number) and changes its name to "sqlite3.h" as
|
31
31
|
** part of the build process.
|
32
32
|
**
|
33
|
-
** @(#) $Id: sqlite.h.in,v 1.
|
33
|
+
** @(#) $Id: sqlite.h.in,v 1.432 2009/02/12 17:07:35 drh Exp $
|
34
34
|
*/
|
35
35
|
#ifndef _SQLITE3_H_
|
36
36
|
#define _SQLITE3_H_
|
@@ -107,8 +107,8 @@ extern "C" {
|
|
107
107
|
** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z
|
108
108
|
** are the major version, minor version, and release number.
|
109
109
|
*/
|
110
|
-
#define SQLITE_VERSION "3.6.
|
111
|
-
#define SQLITE_VERSION_NUMBER
|
110
|
+
#define SQLITE_VERSION "3.6.11"
|
111
|
+
#define SQLITE_VERSION_NUMBER 3006011
|
112
112
|
|
113
113
|
/*
|
114
114
|
** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
|
@@ -2789,8 +2789,10 @@ typedef struct sqlite3_stmt sqlite3_stmt;
|
|
2789
2789
|
** new limit for that construct. The function returns the old limit.
|
2790
2790
|
**
|
2791
2791
|
** If the new limit is a negative number, the limit is unchanged.
|
2792
|
-
** For the limit category of SQLITE_LIMIT_XYZ there is a
|
2793
|
-
**
|
2792
|
+
** For the limit category of SQLITE_LIMIT_XYZ there is a
|
2793
|
+
** [limits | hard upper bound]
|
2794
|
+
** set by a compile-time C preprocessor macro named
|
2795
|
+
** [limits | SQLITE_MAX_XYZ].
|
2794
2796
|
** (The "_LIMIT_" in the name is changed to "_MAX_".)
|
2795
2797
|
** Attempts to increase a limit above its hard upper bound are
|
2796
2798
|
** silently truncated to the hard upper limit.
|
@@ -2798,7 +2800,7 @@ typedef struct sqlite3_stmt sqlite3_stmt;
|
|
2798
2800
|
** Run time limits are intended for use in applications that manage
|
2799
2801
|
** both their own internal database and also databases that are controlled
|
2800
2802
|
** by untrusted external sources. An example application might be a
|
2801
|
-
**
|
2803
|
+
** web browser that has its own databases for storing history and
|
2802
2804
|
** separate databases controlled by JavaScript applications downloaded
|
2803
2805
|
** off the Internet. The internal databases can be given the
|
2804
2806
|
** large, default limits. Databases managed by external sources can
|
@@ -2830,9 +2832,10 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
|
|
2830
2832
|
** CAPI3REF: Run-Time Limit Categories {H12790} <H12760>
|
2831
2833
|
** KEYWORDS: {limit category} {limit categories}
|
2832
2834
|
**
|
2833
|
-
** These constants define various
|
2834
|
-
** that can be
|
2835
|
-
** The meanings of the various limits
|
2835
|
+
** These constants define various performance limits
|
2836
|
+
** that can be lowered at run-time using [sqlite3_limit()].
|
2837
|
+
** The synopsis of the meanings of the various limits is shown below.
|
2838
|
+
** Additional information is available at [limits | Limits in SQLite].
|
2836
2839
|
**
|
2837
2840
|
** <dl>
|
2838
2841
|
** <dt>SQLITE_LIMIT_LENGTH</dt>
|
@@ -2843,7 +2846,7 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
|
|
2843
2846
|
**
|
2844
2847
|
** <dt>SQLITE_LIMIT_COLUMN</dt>
|
2845
2848
|
** <dd>The maximum number of columns in a table definition or in the
|
2846
|
-
** result set of a SELECT or the maximum number of columns in an index
|
2849
|
+
** result set of a [SELECT] or the maximum number of columns in an index
|
2847
2850
|
** or in an ORDER BY or GROUP BY clause.</dd>
|
2848
2851
|
**
|
2849
2852
|
** <dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
|
@@ -2860,11 +2863,11 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
|
|
2860
2863
|
** <dd>The maximum number of arguments on a function.</dd>
|
2861
2864
|
**
|
2862
2865
|
** <dt>SQLITE_LIMIT_ATTACHED</dt>
|
2863
|
-
** <dd>The maximum number of attached databases.</dd>
|
2866
|
+
** <dd>The maximum number of [ATTACH | attached databases].</dd>
|
2864
2867
|
**
|
2865
2868
|
** <dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
|
2866
|
-
** <dd>The maximum length of the pattern argument to the LIKE or
|
2867
|
-
** GLOB operators.</dd>
|
2869
|
+
** <dd>The maximum length of the pattern argument to the [LIKE] or
|
2870
|
+
** [GLOB] operators.</dd>
|
2868
2871
|
**
|
2869
2872
|
** <dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
|
2870
2873
|
** <dd>The maximum number of variables in an SQL statement that can
|
@@ -3099,7 +3102,7 @@ typedef struct sqlite3_context sqlite3_context;
|
|
3099
3102
|
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
|
3100
3103
|
**
|
3101
3104
|
** In the SQL strings input to [sqlite3_prepare_v2()] and its variants,
|
3102
|
-
** literals may be replaced by a parameter in one of these forms:
|
3105
|
+
** literals may be replaced by a [parameter] in one of these forms:
|
3103
3106
|
**
|
3104
3107
|
** <ul>
|
3105
3108
|
** <li> ?
|
@@ -4977,8 +4980,8 @@ int sqlite3_get_autocommit(sqlite3*);
|
|
4977
4980
|
** CAPI3REF: Find The Database Handle Of A Prepared Statement {H13120} <S60600>
|
4978
4981
|
**
|
4979
4982
|
** The sqlite3_db_handle interface returns the [database connection] handle
|
4980
|
-
** to which a [prepared statement] belongs. The database
|
4981
|
-
** sqlite3_db_handle is the same database
|
4983
|
+
** to which a [prepared statement] belongs. The [database connection]
|
4984
|
+
** returned by sqlite3_db_handle is the same [database connection] that was the first argument
|
4982
4985
|
** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
|
4983
4986
|
** create the statement in the first place.
|
4984
4987
|
**
|
@@ -5183,7 +5186,7 @@ void *sqlite3_update_hook(
|
|
5183
5186
|
** to the same database. Sharing is enabled if the argument is true
|
5184
5187
|
** and disabled if the argument is false.
|
5185
5188
|
**
|
5186
|
-
** Cache sharing is enabled and disabled for an entire process.
|
5189
|
+
** Cache sharing is enabled and disabled for an entire process.
|
5187
5190
|
** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
|
5188
5191
|
** sharing was enabled or disabled for each thread separately.
|
5189
5192
|
**
|
@@ -5203,6 +5206,8 @@ void *sqlite3_update_hook(
|
|
5203
5206
|
** future releases of SQLite. Applications that care about shared
|
5204
5207
|
** cache setting should set it explicitly.
|
5205
5208
|
**
|
5209
|
+
** See Also: [SQLite Shared-Cache Mode]
|
5210
|
+
**
|
5206
5211
|
** INVARIANTS:
|
5207
5212
|
**
|
5208
5213
|
** {H10331} A successful invocation of [sqlite3_enable_shared_cache(B)]
|
@@ -6372,6 +6377,7 @@ int sqlite3_test_control(int op, ...);
|
|
6372
6377
|
#define SQLITE_TESTCTRL_BITVEC_TEST 8
|
6373
6378
|
#define SQLITE_TESTCTRL_FAULT_INSTALL 9
|
6374
6379
|
#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10
|
6380
|
+
#define SQLITE_TESTCTRL_PENDING_BYTE 11
|
6375
6381
|
|
6376
6382
|
/*
|
6377
6383
|
** CAPI3REF: SQLite Runtime Status {H17200} <S60200>
|
@@ -6661,17 +6667,17 @@ typedef struct sqlite3_pcache sqlite3_pcache;
|
|
6661
6667
|
** in which case SQLite will attempt to unpin one or more
|
6662
6668
|
** pages before re-requesting the same page, or it can
|
6663
6669
|
** allocate a new page and return a pointer to it. If a new
|
6664
|
-
** page is allocated, then
|
6665
|
-
** it is returned.
|
6670
|
+
** page is allocated, then the first sizeof(void*) bytes of
|
6671
|
+
** it (at least) must be zeroed before it is returned.
|
6666
6672
|
** <tr><td>2<td>If createFlag is set to 2, then SQLite is not holding any
|
6667
6673
|
** pinned pages associated with the specific cache passed
|
6668
6674
|
** as the first argument to xFetch() that can be unpinned. The
|
6669
6675
|
** cache implementation should attempt to allocate a new
|
6670
|
-
** cache entry and return a pointer to it. Again, the
|
6671
|
-
** page should be zeroed before
|
6672
|
-
** method returns NULL when
|
6673
|
-
**
|
6674
|
-
** user.
|
6676
|
+
** cache entry and return a pointer to it. Again, the first
|
6677
|
+
** sizeof(void*) bytes of the page should be zeroed before
|
6678
|
+
** it is returned. If the xFetch() method returns NULL when
|
6679
|
+
** createFlag==2, SQLite assumes that a memory allocation
|
6680
|
+
** failed and returns SQLITE_NOMEM to the user.
|
6675
6681
|
** </table>
|
6676
6682
|
**
|
6677
6683
|
** xUnpin() is called by SQLite with a pointer to a currently pinned page
|
@@ -6722,6 +6728,202 @@ struct sqlite3_pcache_methods {
|
|
6722
6728
|
void (*xDestroy)(sqlite3_pcache*);
|
6723
6729
|
};
|
6724
6730
|
|
6731
|
+
/*
|
6732
|
+
** CAPI3REF: Online Backup Object
|
6733
|
+
** EXPERIMENTAL
|
6734
|
+
**
|
6735
|
+
** The sqlite3_backup object records state information about an ongoing
|
6736
|
+
** online backup operation. The sqlite3_backup object is created by
|
6737
|
+
** a call to [sqlite3_backup_init()] and is destroyed by a call to
|
6738
|
+
** [sqlite3_backup_finish()].
|
6739
|
+
**
|
6740
|
+
** See Also: [Using the SQLite Online Backup API]
|
6741
|
+
*/
|
6742
|
+
typedef struct sqlite3_backup sqlite3_backup;
|
6743
|
+
|
6744
|
+
/*
|
6745
|
+
** CAPI3REF: Online Backup API.
|
6746
|
+
** EXPERIMENTAL
|
6747
|
+
**
|
6748
|
+
** This API is used to overwrite the contents of one database with that
|
6749
|
+
** of another. It is useful either for creating backups of databases or
|
6750
|
+
** for copying in-memory databases to or from persistent files.
|
6751
|
+
**
|
6752
|
+
** See Also: [Using the SQLite Online Backup API]
|
6753
|
+
**
|
6754
|
+
** Exclusive access is required to the destination database for the
|
6755
|
+
** duration of the operation. However the source database is only
|
6756
|
+
** read-locked while it is actually being read, it is not locked
|
6757
|
+
** continuously for the entire operation. Thus, the backup may be
|
6758
|
+
** performed on a live database without preventing other users from
|
6759
|
+
** writing to the database for an extended period of time.
|
6760
|
+
**
|
6761
|
+
** To perform a backup operation:
|
6762
|
+
** <ol>
|
6763
|
+
** <li><b>sqlite3_backup_init()</b> is called once to initialize the
|
6764
|
+
** backup,
|
6765
|
+
** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
|
6766
|
+
** the data between the two databases, and finally
|
6767
|
+
** <li><b>sqlite3_backup_finish()</b> is called to release all resources
|
6768
|
+
** associated with the backup operation.
|
6769
|
+
** </ol>
|
6770
|
+
** There should be exactly one call to sqlite3_backup_finish() for each
|
6771
|
+
** successful call to sqlite3_backup_init().
|
6772
|
+
**
|
6773
|
+
** <b>sqlite3_backup_init()</b>
|
6774
|
+
**
|
6775
|
+
** The first two arguments passed to [sqlite3_backup_init()] are the database
|
6776
|
+
** handle associated with the destination database and the database name
|
6777
|
+
** used to attach the destination database to the handle. The database name
|
6778
|
+
** is "main" for the main database, "temp" for the temporary database, or
|
6779
|
+
** the name specified as part of the [ATTACH] statement if the destination is
|
6780
|
+
** an attached database. The third and fourth arguments passed to
|
6781
|
+
** sqlite3_backup_init() identify the [database connection]
|
6782
|
+
** and database name used
|
6783
|
+
** to access the source database. The values passed for the source and
|
6784
|
+
** destination [database connection] parameters must not be the same.
|
6785
|
+
**
|
6786
|
+
** If an error occurs within sqlite3_backup_init(), then NULL is returned
|
6787
|
+
** and an error code and error message written into the [database connection]
|
6788
|
+
** passed as the first argument. They may be retrieved using the
|
6789
|
+
** [sqlite3_errcode()], [sqlite3_errmsg()], and [sqlite3_errmsg16()] functions.
|
6790
|
+
** Otherwise, if successful, a pointer to an [sqlite3_backup] object is
|
6791
|
+
** returned. This pointer may be used with the sqlite3_backup_step() and
|
6792
|
+
** sqlite3_backup_finish() functions to perform the specified backup
|
6793
|
+
** operation.
|
6794
|
+
**
|
6795
|
+
** <b>sqlite3_backup_step()</b>
|
6796
|
+
**
|
6797
|
+
** Function [sqlite3_backup_step()] is used to copy up to nPage pages between
|
6798
|
+
** the source and destination databases, where nPage is the value of the
|
6799
|
+
** second parameter passed to sqlite3_backup_step(). If nPage is a negative
|
6800
|
+
** value, all remaining source pages are copied. If the required pages are
|
6801
|
+
** succesfully copied, but there are still more pages to copy before the
|
6802
|
+
** backup is complete, it returns [SQLITE_OK]. If no error occured and there
|
6803
|
+
** are no more pages to copy, then [SQLITE_DONE] is returned. If an error
|
6804
|
+
** occurs, then an SQLite error code is returned. As well as [SQLITE_OK] and
|
6805
|
+
** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
|
6806
|
+
** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
|
6807
|
+
** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
|
6808
|
+
**
|
6809
|
+
** As well as the case where the destination database file was opened for
|
6810
|
+
** read-only access, sqlite3_backup_step() may return [SQLITE_READONLY] if
|
6811
|
+
** the destination is an in-memory database with a different page size
|
6812
|
+
** from the source database.
|
6813
|
+
**
|
6814
|
+
** If sqlite3_backup_step() cannot obtain a required file-system lock, then
|
6815
|
+
** the [sqlite3_busy_handler | busy-handler function]
|
6816
|
+
** is invoked (if one is specified). If the
|
6817
|
+
** busy-handler returns non-zero before the lock is available, then
|
6818
|
+
** [SQLITE_BUSY] is returned to the caller. In this case the call to
|
6819
|
+
** sqlite3_backup_step() can be retried later. If the source
|
6820
|
+
** [database connection]
|
6821
|
+
** is being used to write to the source database when sqlite3_backup_step()
|
6822
|
+
** is called, then [SQLITE_LOCKED] is returned immediately. Again, in this
|
6823
|
+
** case the call to sqlite3_backup_step() can be retried later on. If
|
6824
|
+
** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
|
6825
|
+
** [SQLITE_READONLY] is returned, then
|
6826
|
+
** there is no point in retrying the call to sqlite3_backup_step(). These
|
6827
|
+
** errors are considered fatal. At this point the application must accept
|
6828
|
+
** that the backup operation has failed and pass the backup operation handle
|
6829
|
+
** to the sqlite3_backup_finish() to release associated resources.
|
6830
|
+
**
|
6831
|
+
** Following the first call to sqlite3_backup_step(), an exclusive lock is
|
6832
|
+
** obtained on the destination file. It is not released until either
|
6833
|
+
** sqlite3_backup_finish() is called or the backup operation is complete
|
6834
|
+
** and sqlite3_backup_step() returns [SQLITE_DONE]. Additionally, each time
|
6835
|
+
** a call to sqlite3_backup_step() is made a [shared lock] is obtained on
|
6836
|
+
** the source database file. This lock is released before the
|
6837
|
+
** sqlite3_backup_step() call returns. Because the source database is not
|
6838
|
+
** locked between calls to sqlite3_backup_step(), it may be modified mid-way
|
6839
|
+
** through the backup procedure. If the source database is modified by an
|
6840
|
+
** external process or via a database connection other than the one being
|
6841
|
+
** used by the backup operation, then the backup will be transparently
|
6842
|
+
** restarted by the next call to sqlite3_backup_step(). If the source
|
6843
|
+
** database is modified by the using the same database connection as is used
|
6844
|
+
** by the backup operation, then the backup database is transparently
|
6845
|
+
** updated at the same time.
|
6846
|
+
**
|
6847
|
+
** <b>sqlite3_backup_finish()</b>
|
6848
|
+
**
|
6849
|
+
** Once sqlite3_backup_step() has returned [SQLITE_DONE], or when the
|
6850
|
+
** application wishes to abandon the backup operation, the [sqlite3_backup]
|
6851
|
+
** object should be passed to sqlite3_backup_finish(). This releases all
|
6852
|
+
** resources associated with the backup operation. If sqlite3_backup_step()
|
6853
|
+
** has not yet returned [SQLITE_DONE], then any active write-transaction on the
|
6854
|
+
** destination database is rolled back. The [sqlite3_backup] object is invalid
|
6855
|
+
** and may not be used following a call to sqlite3_backup_finish().
|
6856
|
+
**
|
6857
|
+
** The value returned by sqlite3_backup_finish is [SQLITE_OK] if no error
|
6858
|
+
** occurred, regardless or whether or not sqlite3_backup_step() was called
|
6859
|
+
** a sufficient number of times to complete the backup operation. Or, if
|
6860
|
+
** an out-of-memory condition or IO error occured during a call to
|
6861
|
+
** sqlite3_backup_step() then [SQLITE_NOMEM] or an
|
6862
|
+
** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] error code
|
6863
|
+
** is returned. In this case the error code and an error message are
|
6864
|
+
** written to the destination [database connection].
|
6865
|
+
**
|
6866
|
+
** A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() is
|
6867
|
+
** not a permanent error and does not affect the return value of
|
6868
|
+
** sqlite3_backup_finish().
|
6869
|
+
**
|
6870
|
+
** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b>
|
6871
|
+
**
|
6872
|
+
** Each call to sqlite3_backup_step() sets two values stored internally
|
6873
|
+
** by an [sqlite3_backup] object. The number of pages still to be backed
|
6874
|
+
** up, which may be queried by sqlite3_backup_remaining(), and the total
|
6875
|
+
** number of pages in the source database file, which may be queried by
|
6876
|
+
** sqlite3_backup_pagecount().
|
6877
|
+
**
|
6878
|
+
** The values returned by these functions are only updated by
|
6879
|
+
** sqlite3_backup_step(). If the source database is modified during a backup
|
6880
|
+
** operation, then the values are not updated to account for any extra
|
6881
|
+
** pages that need to be updated or the size of the source database file
|
6882
|
+
** changing.
|
6883
|
+
**
|
6884
|
+
** <b>Concurrent Usage of Database Handles</b>
|
6885
|
+
**
|
6886
|
+
** The source [database connection] may be used by the application for other
|
6887
|
+
** purposes while a backup operation is underway or being initialized.
|
6888
|
+
** If SQLite is compiled and configured to support threadsafe database
|
6889
|
+
** connections, then the source database connection may be used concurrently
|
6890
|
+
** from within other threads.
|
6891
|
+
**
|
6892
|
+
** However, the application must guarantee that the destination database
|
6893
|
+
** connection handle is not passed to any other API (by any thread) after
|
6894
|
+
** sqlite3_backup_init() is called and before the corresponding call to
|
6895
|
+
** sqlite3_backup_finish(). Unfortunately SQLite does not currently check
|
6896
|
+
** for this, if the application does use the destination [database connection]
|
6897
|
+
** for some other purpose during a backup operation, things may appear to
|
6898
|
+
** work correctly but in fact be subtly malfunctioning. Use of the
|
6899
|
+
** destination database connection while a backup is in progress might
|
6900
|
+
** also cause a mutex deadlock.
|
6901
|
+
**
|
6902
|
+
** Furthermore, if running in [shared cache mode], the application must
|
6903
|
+
** guarantee that the shared cache used by the destination database
|
6904
|
+
** is not accessed while the backup is running. In practice this means
|
6905
|
+
** that the application must guarantee that the file-system file being
|
6906
|
+
** backed up to is not accessed by any connection within the process,
|
6907
|
+
** not just the specific connection that was passed to sqlite3_backup_init().
|
6908
|
+
**
|
6909
|
+
** The [sqlite3_backup] object itself is partially threadsafe. Multiple
|
6910
|
+
** threads may safely make multiple concurrent calls to sqlite3_backup_step().
|
6911
|
+
** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
|
6912
|
+
** APIs are not strictly speaking threadsafe. If they are invoked at the
|
6913
|
+
** same time as another thread is invoking sqlite3_backup_step() it is
|
6914
|
+
** possible that they return invalid values.
|
6915
|
+
*/
|
6916
|
+
sqlite3_backup *sqlite3_backup_init(
|
6917
|
+
sqlite3 *pDest, /* Destination database handle */
|
6918
|
+
const char *zDestName, /* Destination database name */
|
6919
|
+
sqlite3 *pSource, /* Source database handle */
|
6920
|
+
const char *zSourceName /* Source database name */
|
6921
|
+
);
|
6922
|
+
int sqlite3_backup_step(sqlite3_backup *p, int nPage);
|
6923
|
+
int sqlite3_backup_finish(sqlite3_backup *p);
|
6924
|
+
int sqlite3_backup_remaining(sqlite3_backup *p);
|
6925
|
+
int sqlite3_backup_pagecount(sqlite3_backup *p);
|
6926
|
+
|
6725
6927
|
/*
|
6726
6928
|
** Undo the hack that converts floating point types to integer for
|
6727
6929
|
** builds on processors without floating point support.
|
data/ext/test_error.c
CHANGED
@@ -6,21 +6,20 @@
|
|
6
6
|
* ./test_error
|
7
7
|
*/
|
8
8
|
|
9
|
-
int
|
9
|
+
int test_progress_callback( void* data )
|
10
10
|
{
|
11
|
-
|
11
|
+
fprintf(stderr, "Progress handler callback\n");
|
12
|
+
return 1;
|
12
13
|
}
|
13
14
|
|
14
|
-
void test_error( sqlite3_context* context, int argc, sqlite3_value **argv)
|
15
|
-
{
|
16
|
-
char* msg = (char*)sqlite3_value_text( argv[0] );
|
17
|
-
int code = sqlite3_value_int( argv[1] );
|
18
|
-
|
19
|
-
fprintf( stderr, "Writting error msg '%s' and error_code %d to context\n", msg, code );
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
void abort_if_error( sqlite3* db, char* msg, int rc )
|
17
|
+
{
|
18
|
+
if ( SQLITE_OK != rc ) {
|
19
|
+
fprintf( stderr, "%s: [%d] -> %s\n", msg, sqlite3_errcode( db ), sqlite3_errmsg( db ) );
|
20
|
+
sqlite3_close( db );
|
21
|
+
exit( 1 );
|
22
|
+
}
|
24
23
|
}
|
25
24
|
|
26
25
|
int main( int argc, char **argv )
|
@@ -34,31 +33,15 @@ int main( int argc, char **argv )
|
|
34
33
|
printf("SQLite Version: %s\n", sqlite3_libversion() );
|
35
34
|
|
36
35
|
rc = sqlite3_open_v2( ":memory:", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL );
|
37
|
-
|
38
|
-
fprintf(stderr, "Failure opening database: %s\n", sqlite3_errmsg( db ) );
|
39
|
-
sqlite3_close( db );
|
40
|
-
exit( 1 );
|
41
|
-
}
|
36
|
+
abort_if_error( db, "Failure opening database", rc );
|
42
37
|
|
43
|
-
rc =
|
44
|
-
|
45
|
-
fprintf( stderr, "Failure creating function: %s\n", sqlite3_errmsg( db ) );
|
46
|
-
sqlite3_close( db );
|
47
|
-
exit( 1 );
|
48
|
-
}
|
49
|
-
|
50
|
-
rc = sqlite3_prepare_v2( db, "SELECT test_error('This is an error', 42)", -1, &stmt, &tail );
|
51
|
-
if ( SQLITE_OK != rc ) {
|
52
|
-
fprintf( stderr, "Failure preparing statement: %s\n", sqlite3_errmsg( db ) );
|
53
|
-
sqlite3_close( db );
|
54
|
-
exit( 1 );
|
55
|
-
}
|
38
|
+
rc = sqlite3_exec( db, "CREATE TABLE t1( c1, c2 );", NULL, NULL, NULL );
|
39
|
+
abort_if_error( db, "Failure creating table t1", rc );
|
56
40
|
|
57
|
-
|
58
|
-
printf( "remove rc = %d\n", rc );
|
59
|
-
rc = sqlite3_create_function( db, "test_blah", -1, SQLITE_UTF8, NULL, NULL, NULL, NULL );
|
60
|
-
printf( "remove rc 2 = %d\n", rc );
|
41
|
+
sqlite3_progress_handler( db, 5, test_progress_callback, (void*) NULL );
|
61
42
|
|
43
|
+
rc = sqlite3_prepare_v2( db, "SELECT * FROM t1", -1, &stmt, &tail );
|
44
|
+
abort_if_error( db, "Failure preparing statement", rc );
|
62
45
|
|
63
46
|
rc = sqlite3_step( stmt );
|
64
47
|
if ( SQLITE_ROW != rc ) {
|
@@ -67,10 +50,12 @@ int main( int argc, char **argv )
|
|
67
50
|
printf( "Before finalizing error message is : %s\n", sqlite3_errmsg( db ));
|
68
51
|
}
|
69
52
|
|
70
|
-
rc =
|
71
|
-
|
72
|
-
|
73
|
-
|
53
|
+
rc = sqlite3_finalize( stmt );
|
54
|
+
if ( SQLITE_OK != rc ) {
|
55
|
+
printf( "Return value from sqlite3_finalize : %d\n", rc );
|
56
|
+
printf( "After finalizing errcode is : %d\n", sqlite3_errcode( db ));
|
57
|
+
printf( "After finalizing error message is : %s\n", sqlite3_errmsg( db ));
|
58
|
+
}
|
74
59
|
sqlite3_close( db );
|
75
60
|
return 0;
|
76
61
|
|
data/lib/amalgalite/database.rb
CHANGED
@@ -165,6 +165,7 @@ module Amalgalite
|
|
165
165
|
def close
|
166
166
|
if open? then
|
167
167
|
@api.close
|
168
|
+
@open = false
|
168
169
|
end
|
169
170
|
end
|
170
171
|
|
@@ -551,9 +552,10 @@ module Amalgalite
|
|
551
552
|
|
552
553
|
if block_given? then
|
553
554
|
begin
|
555
|
+
previous_exception = $!
|
554
556
|
return ( yield self )
|
555
557
|
ensure
|
556
|
-
if $! then
|
558
|
+
if $! and ($! != previous_exception) then
|
557
559
|
rollback
|
558
560
|
raise $!
|
559
561
|
else
|