amalgalite 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.415 2008/11/19 01:20:26 drh Exp $
33
+ ** @(#) $Id: sqlite.h.in,v 1.420 2008/12/16 13:46:30 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.6.2"
111
- #define SQLITE_VERSION_NUMBER 3006006
110
+ #define SQLITE_VERSION "3.6.7"
111
+ #define SQLITE_VERSION_NUMBER 3006007
112
112
 
113
113
  /*
114
114
  ** CAPI3REF: Run-Time Library Version Numbers {H10020} <S60100>
@@ -507,6 +507,8 @@ int sqlite3_exec(
507
507
  #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
508
508
  #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
509
509
  #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
510
+ #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
511
+ #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
510
512
 
511
513
  /*
512
514
  ** CAPI3REF: Flags For File Open Operations {H10230} <H11120> <H12700>
@@ -723,6 +725,9 @@ struct sqlite3_io_methods {
723
725
  ** is defined.
724
726
  */
725
727
  #define SQLITE_FCNTL_LOCKSTATE 1
728
+ #define SQLITE_GET_LOCKPROXYFILE 2
729
+ #define SQLITE_SET_LOCKPROXYFILE 3
730
+ #define SQLITE_LAST_ERRNO 4
726
731
 
727
732
  /*
728
733
  ** CAPI3REF: Mutex Handle {H17110} <S20130>
@@ -770,11 +775,11 @@ typedef struct sqlite3_mutex sqlite3_mutex;
770
775
  ** The zName field holds the name of the VFS module. The name must
771
776
  ** be unique across all VFS modules.
772
777
  **
773
- ** {H11141} SQLite will guarantee that the zFilename parameter to xOpen
778
+ ** SQLite will guarantee that the zFilename parameter to xOpen
774
779
  ** is either a NULL pointer or string obtained
775
780
  ** from xFullPathname(). SQLite further guarantees that
776
781
  ** the string will be valid and unchanged until xClose() is
777
- ** called. {END} Because of the previous sentense,
782
+ ** called. Because of the previous sentense,
778
783
  ** the [sqlite3_file] can safely store a pointer to the
779
784
  ** filename if it needs to remember the filename for some reason.
780
785
  ** If the zFilename parameter is xOpen is a NULL pointer then xOpen
@@ -782,14 +787,14 @@ typedef struct sqlite3_mutex sqlite3_mutex;
782
787
  ** xFilename parameter is NULL it will also be the case that the
783
788
  ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
784
789
  **
785
- ** {H11142} The flags argument to xOpen() includes all bits set in
790
+ ** The flags argument to xOpen() includes all bits set in
786
791
  ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
787
792
  ** or [sqlite3_open16()] is used, then flags includes at least
788
- ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. {END}
793
+ ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
789
794
  ** If xOpen() opens a file read-only then it sets *pOutFlags to
790
795
  ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
791
796
  **
792
- ** {H11143} SQLite will also add one of the following flags to the xOpen()
797
+ ** SQLite will also add one of the following flags to the xOpen()
793
798
  ** call, depending on the object being opened:
794
799
  **
795
800
  ** <ul>
@@ -800,7 +805,7 @@ typedef struct sqlite3_mutex sqlite3_mutex;
800
805
  ** <li> [SQLITE_OPEN_TRANSIENT_DB]
801
806
  ** <li> [SQLITE_OPEN_SUBJOURNAL]
802
807
  ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
803
- ** </ul> {END}
808
+ ** </ul>
804
809
  **
805
810
  ** The file I/O implementation can use the object type flags to
806
811
  ** change the way it deals with files. For example, an application
@@ -818,28 +823,28 @@ typedef struct sqlite3_mutex sqlite3_mutex;
818
823
  ** <li> [SQLITE_OPEN_EXCLUSIVE]
819
824
  ** </ul>
820
825
  **
821
- ** {H11145} The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
822
- ** deleted when it is closed. {H11146} The [SQLITE_OPEN_DELETEONCLOSE]
826
+ ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
827
+ ** deleted when it is closed. The [SQLITE_OPEN_DELETEONCLOSE]
823
828
  ** will be set for TEMP databases, journals and for subjournals.
824
829
  **
825
- ** {H11147} The [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened
830
+ ** The [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened
826
831
  ** for exclusive access. This flag is set for all files except
827
832
  ** for the main database file.
828
833
  **
829
- ** {H11148} At least szOsFile bytes of memory are allocated by SQLite
834
+ ** At least szOsFile bytes of memory are allocated by SQLite
830
835
  ** to hold the [sqlite3_file] structure passed as the third
831
- ** argument to xOpen. {END} The xOpen method does not have to
836
+ ** argument to xOpen. The xOpen method does not have to
832
837
  ** allocate the structure; it should just fill it in.
833
838
  **
834
- ** {H11149} The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
839
+ ** The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
835
840
  ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
836
841
  ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
837
- ** to test whether a file is at least readable. {END} The file can be a
842
+ ** to test whether a file is at least readable. The file can be a
838
843
  ** directory.
839
844
  **
840
- ** {H11150} SQLite will always allocate at least mxPathname+1 bytes for the
841
- ** output buffer xFullPathname. {H11151} The exact size of the output buffer
842
- ** is also passed as a parameter to both methods. {END} If the output buffer
845
+ ** SQLite will always allocate at least mxPathname+1 bytes for the
846
+ ** output buffer xFullPathname. The exact size of the output buffer
847
+ ** is also passed as a parameter to both methods. If the output buffer
843
848
  ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
844
849
  ** handled as a fatal error by SQLite, vfs implementations should endeavor
845
850
  ** to prevent this by setting mxPathname to a sufficiently large value.
@@ -853,6 +858,7 @@ typedef struct sqlite3_mutex sqlite3_mutex;
853
858
  ** The xSleep() method causes the calling thread to sleep for at
854
859
  ** least the number of microseconds given. The xCurrentTime()
855
860
  ** method returns a Julian Day Number for the current date and time.
861
+ **
856
862
  */
857
863
  typedef struct sqlite3_vfs sqlite3_vfs;
858
864
  struct sqlite3_vfs {
@@ -869,7 +875,7 @@ struct sqlite3_vfs {
869
875
  int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
870
876
  void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
871
877
  void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
872
- void *(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol);
878
+ void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
873
879
  void (*xDlClose)(sqlite3_vfs*, void*);
874
880
  int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
875
881
  int (*xSleep)(sqlite3_vfs*, int microseconds);
@@ -882,14 +888,14 @@ struct sqlite3_vfs {
882
888
  /*
883
889
  ** CAPI3REF: Flags for the xAccess VFS method {H11190} <H11140>
884
890
  **
885
- ** {H11191} These integer constants can be used as the third parameter to
891
+ ** These integer constants can be used as the third parameter to
886
892
  ** the xAccess method of an [sqlite3_vfs] object. {END} They determine
887
893
  ** what kind of permissions the xAccess method is looking for.
888
- ** {H11192} With SQLITE_ACCESS_EXISTS, the xAccess method
894
+ ** With SQLITE_ACCESS_EXISTS, the xAccess method
889
895
  ** simply checks whether the file exists.
890
- ** {H11193} With SQLITE_ACCESS_READWRITE, the xAccess method
896
+ ** With SQLITE_ACCESS_READWRITE, the xAccess method
891
897
  ** checks whether the file is both readable and writable.
892
- ** {H11194} With SQLITE_ACCESS_READ, the xAccess method
898
+ ** With SQLITE_ACCESS_READ, the xAccess method
893
899
  ** checks whether the file is readable.
894
900
  */
895
901
  #define SQLITE_ACCESS_EXISTS 0
@@ -1044,7 +1050,7 @@ int sqlite3_os_end(void);
1044
1050
  ** S is a pointer to an aligned memory buffer not less than
1045
1051
  ** Z*N bytes in size shall cause S to be used by the
1046
1052
  ** [scratch memory allocator] for as many as N simulataneous
1047
- ** allocations each of size Z.
1053
+ ** allocations each of size (Z & ~7).
1048
1054
  **
1049
1055
  ** {H14153} A successful call to [sqlite3_config]([SQLITE_CONFIG_SCRATCH],S,Z,N)
1050
1056
  ** where S is a NULL pointer shall disable the
@@ -1056,7 +1062,7 @@ int sqlite3_os_end(void);
1056
1062
  ** S is a pointer to an aligned memory buffer not less than
1057
1063
  ** Z*N bytes in size shall cause S to be used by the
1058
1064
  ** [pagecache memory allocator] for as many as N simulataneous
1059
- ** allocations each of size Z.
1065
+ ** allocations each of size (Z & ~7).
1060
1066
  **
1061
1067
  ** {H14159} A successful call to
1062
1068
  ** [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],S,Z,N)
@@ -1404,18 +1410,18 @@ int sqlite3_extended_result_codes(sqlite3*, int onoff);
1404
1410
  ** CAPI3REF: Last Insert Rowid {H12220} <S10700>
1405
1411
  **
1406
1412
  ** Each entry in an SQLite table has a unique 64-bit signed
1407
- ** integer key called the "rowid". The rowid is always available
1413
+ ** integer key called the [ROWID | "rowid"]. The rowid is always available
1408
1414
  ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
1409
1415
  ** names are not also used by explicitly declared columns. If
1410
- ** the table has a column of type INTEGER PRIMARY KEY then that column
1416
+ ** the table has a column of type [INTEGER PRIMARY KEY] then that column
1411
1417
  ** is another alias for the rowid.
1412
1418
  **
1413
- ** This routine returns the rowid of the most recent
1419
+ ** This routine returns the [rowid] of the most recent
1414
1420
  ** successful [INSERT] into the database from the [database connection]
1415
1421
  ** in the first argument. If no successful [INSERT]s
1416
1422
  ** have ever occurred on that database connection, zero is returned.
1417
1423
  **
1418
- ** If an [INSERT] occurs within a trigger, then the rowid of the inserted
1424
+ ** If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
1419
1425
  ** row is returned by this routine as long as the trigger is running.
1420
1426
  ** But once the trigger terminates, the value returned by this routine
1421
1427
  ** reverts to the last value inserted before the trigger fired.
@@ -1435,7 +1441,8 @@ int sqlite3_extended_result_codes(sqlite3*, int onoff);
1435
1441
  **
1436
1442
  ** INVARIANTS:
1437
1443
  **
1438
- ** {H12221} The [sqlite3_last_insert_rowid()] function shall return the rowid
1444
+ ** {H12221} The [sqlite3_last_insert_rowid()] function shall return
1445
+ ** the [rowid]
1439
1446
  ** of the most recent successful [INSERT] performed on the same
1440
1447
  ** [database connection] and within the same or higher level
1441
1448
  ** trigger context, or zero if there have been no qualifying
@@ -1449,10 +1456,10 @@ int sqlite3_extended_result_codes(sqlite3*, int onoff);
1449
1456
  **
1450
1457
  ** {A12232} If a separate thread performs a new [INSERT] on the same
1451
1458
  ** database connection while the [sqlite3_last_insert_rowid()]
1452
- ** function is running and thus changes the last insert rowid,
1459
+ ** function is running and thus changes the last insert [rowid],
1453
1460
  ** then the value returned by [sqlite3_last_insert_rowid()] is
1454
1461
  ** unpredictable and might not equal either the old or the new
1455
- ** last insert rowid.
1462
+ ** last insert [rowid].
1456
1463
  */
1457
1464
  sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
1458
1465
 
@@ -2163,8 +2170,8 @@ sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
2163
2170
  ** CAPI3REF: Pseudo-Random Number Generator {H17390} <S20000>
2164
2171
  **
2165
2172
  ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
2166
- ** select random ROWIDs when inserting new records into a table that
2167
- ** already uses the largest possible ROWID. The PRNG is also used for
2173
+ ** select random [ROWID | ROWIDs] when inserting new records into a table that
2174
+ ** already uses the largest possible [ROWID]. The PRNG is also used for
2168
2175
  ** the build-in random() and randomblob() SQL functions. This interface allows
2169
2176
  ** applications to access the same PRNG for other purposes.
2170
2177
  **
@@ -5113,8 +5120,8 @@ void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5113
5120
  ** to be invoked.
5114
5121
  ** The third and fourth arguments to the callback contain pointers to the
5115
5122
  ** database and table name containing the affected row.
5116
- ** The final callback parameter is the rowid of the row. In the case of
5117
- ** an update, this is the rowid after the update takes place.
5123
+ ** The final callback parameter is the [rowid] of the row.
5124
+ ** In the case of an update, this is the [rowid] after the update takes place.
5118
5125
  **
5119
5126
  ** The update hook is not invoked when internal system tables are
5120
5127
  ** modified (i.e. sqlite_master and sqlite_sequence).
@@ -5157,7 +5164,7 @@ void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
5157
5164
  ** to zero-terminated UTF-8 strings which are the names of the
5158
5165
  ** database and table that is being updated.
5159
5166
 
5160
- ** {H12985} The final callback parameter is the rowid of the row after
5167
+ ** {H12985} The final callback parameter is the [rowid] of the row after
5161
5168
  ** the change occurs.
5162
5169
  */
5163
5170
  void *sqlite3_update_hook(
@@ -5323,7 +5330,7 @@ void sqlite3_soft_heap_limit(int);
5323
5330
  ** <tr><td> 6th <td> const char* <td> Name of default collation sequence
5324
5331
  ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint
5325
5332
  ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY
5326
- ** <tr><td> 9th <td> int <td> True if column is AUTOINCREMENT
5333
+ ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
5327
5334
  ** </table>
5328
5335
  ** </blockquote>
5329
5336
  **
@@ -5334,9 +5341,9 @@ void sqlite3_soft_heap_limit(int);
5334
5341
  ** If the specified table is actually a view, an [error code] is returned.
5335
5342
  **
5336
5343
  ** If the specified column is "rowid", "oid" or "_rowid_" and an
5337
- ** INTEGER PRIMARY KEY column has been explicitly declared, then the output
5344
+ ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
5338
5345
  ** parameters are set for the explicitly declared column. If there is no
5339
- ** explicitly declared INTEGER PRIMARY KEY column, then the output
5346
+ ** explicitly declared [INTEGER PRIMARY KEY] column, then the output
5340
5347
  ** parameters are set as follows:
5341
5348
  **
5342
5349
  ** <pre>
@@ -5443,7 +5450,7 @@ int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5443
5450
  **
5444
5451
  ** {H12644} Automatic extensions apply across all threads.
5445
5452
  */
5446
- int sqlite3_auto_extension(void *xEntryPoint);
5453
+ int sqlite3_auto_extension(void (*xEntryPoint)(void));
5447
5454
 
5448
5455
  /*
5449
5456
  ** CAPI3REF: Reset Automatic Extension Loading {H12660} <S20500>
@@ -5760,7 +5767,7 @@ typedef struct sqlite3_blob sqlite3_blob;
5760
5767
  ** in other words, the same BLOB that would be selected by:
5761
5768
  **
5762
5769
  ** <pre>
5763
- ** SELECT zColumn FROM zDb.zTable WHERE rowid = iRow;
5770
+ ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
5764
5771
  ** </pre> {END}
5765
5772
  **
5766
5773
  ** If the flags parameter is non-zero, the the BLOB is opened for read
@@ -0,0 +1,77 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include "sqlite3.h"
4
+ /**
5
+ * gcc -o test_error test_error.c sqlite3.c
6
+ * ./test_error
7
+ */
8
+
9
+ int callback( void *unused, int argc, char **argv, char **col_name )
10
+ {
11
+ return 0;
12
+ }
13
+
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
+
21
+ sqlite3_result_error( context, msg, -1 );
22
+ sqlite3_result_error_code( context, code);
23
+ return;
24
+ }
25
+
26
+ int main( int argc, char **argv )
27
+ {
28
+ sqlite3 *db;
29
+ sqlite3_stmt *stmt;
30
+ const char *tail;
31
+ char *errmsg;
32
+ int rc;
33
+
34
+ printf("SQLite Version: %s\n", sqlite3_libversion() );
35
+
36
+ rc = sqlite3_open_v2( ":memory:", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL );
37
+ if ( SQLITE_OK != rc ) {
38
+ fprintf(stderr, "Failure opening database: %s\n", sqlite3_errmsg( db ) );
39
+ sqlite3_close( db );
40
+ exit( 1 );
41
+ }
42
+
43
+ rc = sqlite3_create_function( db, "test_error", 2, SQLITE_UTF8, NULL, test_error, NULL, NULL );
44
+ if ( SQLITE_OK != rc ) {
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
+ }
56
+
57
+ rc = sqlite3_create_function( db, "test_error", 2, SQLITE_UTF8, NULL, NULL, NULL, NULL );
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 );
61
+
62
+
63
+ rc = sqlite3_step( stmt );
64
+ if ( SQLITE_ROW != rc ) {
65
+ printf( "Return code from sqlite3_step : %d\n", rc );
66
+ printf( "Before finalizing error code is : %d\n", sqlite3_errcode( db ));
67
+ printf( "Before finalizing error message is : %s\n", sqlite3_errmsg( db ));
68
+ }
69
+
70
+ rc = sqlite3_reset( stmt );
71
+ printf( "Return value from sqlite3_finalize : %d\n", rc );
72
+ printf( "After finalizing errcode is : %d\n", sqlite3_errcode( db ));
73
+ printf( "After finalizing error message is : %s\n", sqlite3_errmsg( db ));
74
+ sqlite3_close( db );
75
+ return 0;
76
+
77
+ }
@@ -15,13 +15,18 @@ module Amalgalite
15
15
  #
16
16
  class Error < ::StandardError; end
17
17
  end
18
+
19
+ require 'amalgalite/aggregate'
18
20
  require 'amalgalite/blob'
19
21
  require 'amalgalite/boolean'
22
+ require 'amalgalite/busy_timeout'
20
23
  require 'amalgalite/column'
21
24
  require 'amalgalite/database'
25
+ require 'amalgalite/function'
22
26
  require 'amalgalite/index'
23
27
  require 'amalgalite/paths'
24
28
  require 'amalgalite/profile_tap'
29
+ require 'amalgalite/progress_handler'
25
30
  require 'amalgalite/schema'
26
31
  require 'amalgalite/sqlite3'
27
32
  require 'amalgalite/statement'
@@ -0,0 +1,67 @@
1
+ require 'amalgalite/sqlite3/database/function'
2
+ module Amalgalite
3
+ #
4
+ # A Base class to inherit from for creating your own SQL aggregate functions
5
+ # in ruby.
6
+ #
7
+ # These are SQL functions similar to _max(X)_, _count(X)_, _avg(X)_. The built
8
+ # in SQLite aggregate functions are:
9
+ #
10
+ # * http://www.sqlite.org/lang_aggfunc.html
11
+ #
12
+ # If you choose to use Aggregate as a parent class of your SQL scalar function
13
+ # implementation you must:
14
+ #
15
+ # * implement _initalize()_ with 0 arguments
16
+ # * set the @arity data member
17
+ # * set the @name data member
18
+ # * implement _step_ with arity of +@arity+
19
+ # * implement _finalize_ with arity of 0
20
+ #
21
+ # For instance to implement a _unique_word_count(X)_ aggregate function you could
22
+ # implement it as:
23
+ #
24
+ # class UniqueWordCount < ::Amalgalite::Aggregate
25
+ # attr_accessor :words
26
+ #
27
+ # def initialize
28
+ # @name = 'unique_word_count'
29
+ # @arity = 1
30
+ # @words = Hash.new { |h,k| h[k] = 0 }
31
+ # end
32
+ #
33
+ # def step( str )
34
+ # str.split(/\W+/).each do |word|
35
+ # words[ word.downcase ] += 1
36
+ # end
37
+ # return nil
38
+ # end
39
+ #
40
+ # def finalize
41
+ # return words.size
42
+ # end
43
+ # end
44
+ #
45
+ #
46
+ class Aggregate
47
+ # The name of the SQL function
48
+ attr_accessor :name
49
+
50
+ # The arity of the SQL function
51
+ attr_accessor :arity
52
+
53
+ # finalize should return the final value of the aggregate function
54
+ def finalize
55
+ raise NotImplementedError, "Aggregate#finalize must be implemented"
56
+ end
57
+
58
+ # <b>Do Not Override</b>
59
+ #
60
+ # The function signature for use by the Amaglaite datase in tracking
61
+ # function creation.
62
+ #
63
+ def signature
64
+ @signature ||= ::Amalgalite::SQLite3::Database::Function.signature( self.name, self.arity )
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,47 @@
1
+ module Amalgalite
2
+ ##
3
+ # A base class for use in creating your own busy handler classes
4
+ #
5
+ class BusyHandler
6
+ def to_proc
7
+ self
8
+ end
9
+
10
+ # the arity of the call method
11
+ def arity() 1 ; end
12
+
13
+ ##
14
+ # Override this method, returning +false+ if the SQLite should return
15
+ # SQLITE_BUSY for all parties involved in the lock, and anything else if the
16
+ # lock attempt should be tried again.
17
+ def call( count )
18
+ raise NotImplementedError, "The busy handler call(N) method must be implemented"
19
+ end
20
+ end
21
+
22
+ ##
23
+ # A busy time out class for use in Database#define_busy_handler
24
+ #
25
+ class BusyTimeout < BusyHandler
26
+ attr_reader :call_count
27
+ ##
28
+ # intialize by setting _count_ and _duration_ ( in milliseconds ).
29
+ #
30
+ def initialize( count = 20 , duration = 50 )
31
+ @count = count
32
+ @duration = duration.to_f / 1_000
33
+ @call_count = 0
34
+ end
35
+
36
+ ##
37
+ # return +false+ if _callcount_ is > _count_ otherwise sleep for _duration_
38
+ # milliseconds and then return +true+
39
+ #
40
+ def call( call_count )
41
+ @call_count = call_count
42
+ return false if ( call_count > @count )
43
+ sleep @duration
44
+ return true
45
+ end
46
+ end
47
+ end