nano-store 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +3 -0
  2. data/.gitmodules +3 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +193 -0
  7. data/Rakefile +1 -0
  8. data/app/app_delegate.rb +5 -0
  9. data/lib/nano-store.rb +1 -0
  10. data/lib/nano_store/bag.rb +98 -0
  11. data/lib/nano_store/model.rb +142 -0
  12. data/lib/nano_store/nano_store.rb +36 -0
  13. data/lib/nano_store/store_extension.rb +150 -0
  14. data/lib/nano_store/version.rb +3 -0
  15. data/lib/nano_store.rb +14 -0
  16. data/nano-store.gemspec +17 -0
  17. data/resources/.gitignore +0 -0
  18. data/spec/bag_spec.rb +66 -0
  19. data/spec/model_spec.rb +130 -0
  20. data/spec/nano_store_spec.rb +48 -0
  21. data/spec/store_extension_spec.rb +110 -0
  22. data/vendor/NanoStore/Classes/Advanced/NSFNanoEngine.h +542 -0
  23. data/vendor/NanoStore/Classes/Advanced/NSFNanoEngine.m +1781 -0
  24. data/vendor/NanoStore/Classes/Advanced/NSFNanoResult.h +137 -0
  25. data/vendor/NanoStore/Classes/Advanced/NSFNanoResult.m +265 -0
  26. data/vendor/NanoStore/Classes/Private/NSFNanoBag_Private.h +37 -0
  27. data/vendor/NanoStore/Classes/Private/NSFNanoEngine_Private.h +69 -0
  28. data/vendor/NanoStore/Classes/Private/NSFNanoExpression_Private.h +35 -0
  29. data/vendor/NanoStore/Classes/Private/NSFNanoGlobals_Private.h +99 -0
  30. data/vendor/NanoStore/Classes/Private/NSFNanoObject_Private.h +35 -0
  31. data/vendor/NanoStore/Classes/Private/NSFNanoPredicate_Private.h +35 -0
  32. data/vendor/NanoStore/Classes/Private/NSFNanoResult_Private.h +43 -0
  33. data/vendor/NanoStore/Classes/Private/NSFNanoSearch_Private.h +48 -0
  34. data/vendor/NanoStore/Classes/Private/NSFNanoStore_Private.h +57 -0
  35. data/vendor/NanoStore/Classes/Private/NanoStore_Private.h +37 -0
  36. data/vendor/NanoStore/Classes/Public/NSFNanoBag.h +306 -0
  37. data/vendor/NanoStore/Classes/Public/NSFNanoBag.m +485 -0
  38. data/vendor/NanoStore/Classes/Public/NSFNanoExpression.h +125 -0
  39. data/vendor/NanoStore/Classes/Public/NSFNanoExpression.m +103 -0
  40. data/vendor/NanoStore/Classes/Public/NSFNanoGlobals.h +323 -0
  41. data/vendor/NanoStore/Classes/Public/NSFNanoGlobals.m +145 -0
  42. data/vendor/NanoStore/Classes/Public/NSFNanoObject.h +298 -0
  43. data/vendor/NanoStore/Classes/Public/NSFNanoObject.m +187 -0
  44. data/vendor/NanoStore/Classes/Public/NSFNanoObjectProtocol.h +119 -0
  45. data/vendor/NanoStore/Classes/Public/NSFNanoPredicate.h +123 -0
  46. data/vendor/NanoStore/Classes/Public/NSFNanoPredicate.m +130 -0
  47. data/vendor/NanoStore/Classes/Public/NSFNanoSearch.h +381 -0
  48. data/vendor/NanoStore/Classes/Public/NSFNanoSearch.m +835 -0
  49. data/vendor/NanoStore/Classes/Public/NSFNanoSortDescriptor.h +124 -0
  50. data/vendor/NanoStore/Classes/Public/NSFNanoSortDescriptor.m +79 -0
  51. data/vendor/NanoStore/Classes/Public/NSFNanoStore.h +475 -0
  52. data/vendor/NanoStore/Classes/Public/NSFNanoStore.m +1375 -0
  53. data/vendor/NanoStore/Classes/Public/NanoStore.h +463 -0
  54. data/vendor/NanoStore/LICENSE +25 -0
  55. data/vendor/NanoStore/NanoStore.bridgesupport +1215 -0
  56. data/vendor/NanoStore/README.md +411 -0
  57. metadata +118 -0
@@ -0,0 +1,103 @@
1
+ /*
2
+ NSFNanoExpression.m
3
+ NanoStore
4
+
5
+ Copyright (c) 2010 Webbo, L.L.C. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted
8
+ provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
11
+ and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
+ * Neither the name of Webbo nor the names of its contributors may be used to endorse or promote
15
+ products derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
25
+ */
26
+
27
+ #import "NSFNanoExpression.h"
28
+ #import "NanoStore_Private.h"
29
+
30
+ @implementation NSFNanoExpression
31
+ {
32
+ /** \cond */
33
+ NSMutableArray *predicates;
34
+ NSMutableArray *operators;
35
+ /** \endcond */
36
+ }
37
+
38
+ @synthesize predicates, operators;
39
+
40
+ + (NSFNanoExpression*)expressionWithPredicate:(NSFNanoPredicate *)aPredicate
41
+ {
42
+ if (nil == aPredicate)
43
+ [[NSException exceptionWithName:NSFUnexpectedParameterException
44
+ reason:[NSString stringWithFormat:@"*** -[%@ %s]: the predicate is nil.", [self class], _cmd]
45
+ userInfo:nil]raise];
46
+
47
+ return [[self alloc]initWithPredicate:aPredicate];
48
+ }
49
+
50
+ - (id)initWithPredicate:(NSFNanoPredicate *)aPredicate
51
+ {
52
+ if (nil == aPredicate)
53
+ [[NSException exceptionWithName:NSFUnexpectedParameterException
54
+ reason:[NSString stringWithFormat:@"*** -[%@ %s]: the predicate is nil.", [self class], _cmd]
55
+ userInfo:nil]raise];
56
+
57
+ if ((self = [super init])) {
58
+ predicates = [NSMutableArray new];
59
+ [predicates addObject:aPredicate];
60
+ operators = [NSMutableArray new];
61
+ [operators addObject:[NSNumber numberWithInt:NSFAnd]];
62
+ }
63
+
64
+ return self;
65
+ }
66
+
67
+ /** \cond */
68
+
69
+
70
+ /** \endcond */
71
+
72
+ #pragma mark -
73
+
74
+ - (void)addPredicate:(NSFNanoPredicate *)aPredicate withOperator:(NSFOperator)someOperator
75
+ {
76
+ if (nil == aPredicate)
77
+ [[NSException exceptionWithName:NSFUnexpectedParameterException
78
+ reason:[NSString stringWithFormat:@"*** -[%@ %s]: the predicate is nil.", [self class], _cmd]
79
+ userInfo:nil]raise];
80
+
81
+ [predicates addObject:aPredicate];
82
+ [operators addObject:[NSNumber numberWithInt:someOperator]];
83
+ }
84
+
85
+ - (NSString *)description
86
+ {
87
+ NSUInteger i, count = [predicates count];
88
+ NSMutableArray *values = [NSMutableArray new];
89
+
90
+ // We always have one predicate, so make sure add it
91
+ [values addObject:[[predicates objectAtIndex:0]description]];
92
+
93
+ for (i = 1; i < count; i++) {
94
+ NSString *compound = [[NSString alloc]initWithFormat:@" %@ %@", ([[operators objectAtIndex:i]intValue] == NSFAnd) ? @"AND" : @"OR", [[predicates objectAtIndex:i]description]];
95
+ [values addObject:compound];
96
+ }
97
+
98
+ NSString *value = [values componentsJoinedByString:@""];
99
+
100
+ return value;
101
+ }
102
+
103
+ @end
@@ -0,0 +1,323 @@
1
+ /*
2
+ NSFNanoGlobals.h
3
+ NanoStore
4
+
5
+ Copyright (c) 2010 Webbo, L.L.C. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted
8
+ provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
11
+ and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
+ * Neither the name of Webbo nor the names of its contributors may be used to endorse or promote
15
+ products derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
25
+ */
26
+
27
+ #import <Foundation/Foundation.h>
28
+
29
+ /*! @file NSFNanoGlobals.h
30
+ @brief Public available constants to be used in NanoStore.
31
+ */
32
+
33
+ /** * If turned on, NanoStore will log debugging information to Console. */
34
+ extern void NSFSetIsDebugOn (BOOL flag);
35
+
36
+ /** * Determine whether NanoStore debugging services are turned on. */
37
+ extern BOOL NSFIsDebugOn (void);
38
+
39
+ /** * The mode used by NSFNanoEngine to manipulate data in the document store.
40
+ * If FastMode is activated, the document store is opened with all performance turned on (more risky in case of failure). Deactivating it makes it slower,
41
+ * but safer.
42
+ *
43
+ * When FastMode is activated NanoStore continues without pausing as soon as it has handed data off to the operating system.
44
+ * If the application running NanoStore crashes, the data will be safe, but the database might become corrupted if the operating system crashes
45
+ * or the computer loses power before that data has been written to the disk surface.
46
+ * On the other hand, some operations are as much as 50 or more times faster with FastMode activated.
47
+ *
48
+ * If FastMode is deactivated, NanoStore will pause at critical moments to make sure that data has actually been written to the disk surface
49
+ * before continuing. This ensures that if the operating system crashes or if there is a power failure, the database will be uncorrupted after rebooting.
50
+ * Deactivating FastMode is very safe, but it is also slower.
51
+ */
52
+ typedef enum {
53
+ /** * The default mode is slower but safer. */
54
+ NSFEngineProcessingDefaultMode = 1,
55
+ /** * The fast mode is very quick but unsafe. */
56
+ NSFEngineProcessingFastMode
57
+ } NSFEngineProcessingMode;
58
+
59
+ /** * Datatypes used by NanoStore.
60
+ @note Additional information can be found on the SQLite website: http://www.sqlite.org/datatype3.html
61
+ */
62
+ typedef enum {
63
+ /** * Used when NanoStore doesn't know the datatype it has read back from the document store. Its string value equivalent is <b>UNKNOWN</b>.*/
64
+ NSFNanoTypeUnknown = -1,
65
+ /** * Used to define the <i>RowID</i> column type in SQLite tables. Only used if you create your own table via NSFNanoEngine. Its string equivalent is <b>INTEGER</b>. */
66
+ NSFNanoTypeRowUID,
67
+ /** * Used to store NSData elements. Its string equivalent is <b>BLOB</b>. */
68
+ NSFNanoTypeData,
69
+ /** * Used to store NSString elements. Its string equivalent is <b>BLOB</b>. */
70
+ NSFNanoTypeString,
71
+ /** * Used to store NSDate elements in the format <i>yyyy-MM-dd HH:mm:ss:SSS</i>. Its string equivalent is <b>TEXT</b>. */
72
+ NSFNanoTypeDate,
73
+ /** * Used to store NSNumber elements. Its string equivalent is <b>REAL</b>. */
74
+ NSFNanoTypeNumber
75
+ } NSFNanoDatatype;
76
+
77
+ /** * Returns the name of a NSFNanoDatatype datatype as a string. */
78
+ extern NSString * NSFStringFromNanoDataType (NSFNanoDatatype aNanoDatatype);
79
+
80
+ /** * Obtains a NSFNanoDatatype datatype by name. */
81
+ extern NSFNanoDatatype NSFNanoDatatypeFromString (NSString *aNanoDatatype);
82
+
83
+ /** * Types of backing store supported by NanoStore.
84
+ * These values represent the storage options available when generating a NanoStore.
85
+ @see NSFNanoStore
86
+ */
87
+ typedef enum {
88
+ /** * Create the transient backing store in RAM. Its contents are lost when the process exits. Fastest, uses more RAM. */
89
+ NSFMemoryStoreType = 1,
90
+ /** * Create a transient temporary backing store on disk. Its contents are lost when the process exits. Slower, uses less RAM than NSFMemoryStoreType. */
91
+ NSFTemporaryStoreType,
92
+ /** * Create a persistant backing store on disk. Its contents are lost when the process exits. Slower, uses less RAM than NSFMemoryStoreType. */
93
+ NSFPersistentStoreType
94
+ } NSFNanoStoreType;
95
+
96
+ /** * Aggregate functions.
97
+ * These functions represent the options available to obtain aggregate results quickly and efficiently.
98
+ * @note Instead of sum(), total() is invoked instead because sum() will throw an "integer overflow" exception
99
+ * if all inputs are integers or NULL and an integer overflow occurs at any point during the computation. On
100
+ * the other hand, total() never throws an integer overflow.
101
+ @see \link NSFNanoSearch::aggregateOperation:onAttribute: -(NSNumber *)aggregateOperation:(NSFAggregateFunctionType)theFunctionType onAttribute:(NSString *)theAttribute \endlink
102
+ */
103
+
104
+ typedef enum {
105
+ /** * It invokes the avg() function. */
106
+ NSFAverage = 1,
107
+ /** * It invokes the count() function. */
108
+ NSFCount,
109
+ /** * It invokes the max() function. */
110
+ NSFMax,
111
+ /** * It invokes the min() function. */
112
+ NSFMin,
113
+ /** * It invokes the total() function. See note above for additional information. */
114
+ NSFTotal
115
+ } NSFAggregateFunctionType;
116
+
117
+ /** * Comparison options.
118
+ * These values represent the options available to some of the classes’ search and comparison methods.
119
+ @see NSFNanoPredicate, NSFNanoSearch
120
+ */
121
+ typedef enum {
122
+ /** * Equal to (case sensitive) */
123
+ NSFEqualTo = 0,
124
+ /** * Begins with (case sensitive) */
125
+ NSFBeginsWith,
126
+ /** * Contains (case sensitive) */
127
+ NSFContains,
128
+ /** * Ends with (case sensitive) */
129
+ NSFEndsWith,
130
+
131
+ /** * Equal to (case insensitive) */
132
+ NSFInsensitiveEqualTo,
133
+ /** * Begins with (case insensitive) */
134
+ NSFInsensitiveBeginsWith,
135
+ /** * Contains (case insensitive) */
136
+ NSFInsensitiveContains,
137
+ /** * Ends with (case insensitive) */
138
+ NSFInsensitiveEndsWith,
139
+
140
+ /** * Greater Ththanan */
141
+ NSFGreaterThan,
142
+ /** * Less than */
143
+ NSFLessThan
144
+ } NSFMatchType;
145
+
146
+ /** * Column types for the Attributes table.
147
+ * These values represent the columns available used for searching.
148
+ @see NSFNanoPredicate
149
+ */
150
+ typedef enum {
151
+ /** * The key column. */
152
+ NSFKeyColumn = 1,
153
+ /** * The attribute column. */
154
+ NSFAttributeColumn,
155
+ /** * The value column. */
156
+ NSFValueColumn
157
+ } NSFTableColumnType;
158
+
159
+ /** * Comparison criteria operators.
160
+ * These values represent the operations available for concatenating predicates in an expression.
161
+ @see NSFNanoExpression, NSFNanoPredicate
162
+ */
163
+ typedef enum {
164
+ /** * And */
165
+ NSFAnd = 1,
166
+ /** * Or */
167
+ NSFOr,
168
+ } NSFOperator;
169
+
170
+ /** * Date comparison options.
171
+ * These values represent the options available when searching and comparing dates.
172
+ @see NSFNanoSearch, NSFNanoPredicate
173
+ */
174
+ typedef enum {
175
+ /** * Before the specified date */
176
+ NSFBeforeDate = 1,
177
+ /** * On the exact date */
178
+ NSFOnDate,
179
+ /** * After the specified date */
180
+ NSFAfterDate
181
+ } NSFDateMatchType;
182
+
183
+ /** * Obtaining search results options.
184
+ * These values represent the options used by the search mechanism to return results.
185
+ @see NSFNanoSearch
186
+ */
187
+ typedef enum {
188
+ /** * Returns the objects. */
189
+ NSFReturnObjects = 1,
190
+ /** * Returns the keys */
191
+ NSFReturnKeys,
192
+ } NSFReturnType;
193
+
194
+ /** * Caching mechanism options.
195
+ * These values represent the options used by the search mechanism to cache results.
196
+ @see NSFNanoEngine
197
+ */
198
+ typedef enum {
199
+ /** * Load data at as soon as it's available. Uses more memory, but data is available quicker. */
200
+ CacheAllData = 1,
201
+ /** * Loads data lazily. First access to data is slow because it retrieves it from disk, but is faster on subsequent requests because the data already exists in memory. */
202
+ CacheDataOnDemand,
203
+ /** * Don't cache data. Slowest mode, uses less memory because it retrieves data from disk every time it's needed. */
204
+ DoNotCacheData,
205
+ } NSFCacheMethod;
206
+
207
+ /** * Text encoding options.
208
+ * The following constants are provided by SQLite as possible string encodings.
209
+ @see NSFNanoEngine
210
+ */
211
+ typedef enum {
212
+ /** * An 8-bit representation of Unicode characters. */
213
+ NSFEncodingUTF8 = 1,
214
+ /** * A 16-bit representation of Unicode characters. */
215
+ NSFEncodingUTF16,
216
+ /** * The encoding representation could not be determined. */
217
+ NSFEncodingUnknown
218
+ } NSFEncodingType;
219
+
220
+ /** * Synchronous options.
221
+ * These values represent the options used to manipulate the synchronous flag. In NSFNanoEngine it's obtained via
222
+ * \link NSFNanoEngine::setSynchronousMode: - (void)setSynchronousMode:(NSFSynchronousMode)theSynchronousMode \endlink
223
+
224
+ @see NSFNanoStore, NSFNanoEngine
225
+ */
226
+ typedef enum {
227
+ /** * SQLite continues without pausing as soon as it has handed data off to the operating system.
228
+ If the application running SQLite crashes, the data will be safe, but the database might become corrupted if
229
+ the operating system crashes or the computer loses power before that data has been written to the disk surface.
230
+ On the other hand, some operations are as much as 50 or more times faster with synchronous OFF. */
231
+ SynchronousModeOff = 0,
232
+ /** * SQLite will still pause at the most critical moments, but less often than in FULL mode.
233
+ There is a very small (though non-zero) chance that a power failure at just the wrong time could corrupt the database
234
+ in NORMAL mode. But in practice, you are more likely to suffer a catastrophic disk failure or some other unrecoverable
235
+ hardware fault. */
236
+ SynchronousModeNormal,
237
+ /** * SQLite will pause at critical moments to make sure that data has actually been written to
238
+ the disk surface before continuing. This ensures that if the operating system crashes or if there is a power failure,
239
+ the database will be uncorrupted after rebooting. FULL synchronous is very safe, but it is also slower. */
240
+ SynchronousModeFull,
241
+ } NSFSynchronousMode;
242
+
243
+ /** * Temporary files location options.
244
+ * These values represent the options used by SQLite to create the temporary files it creates.
245
+ @see NSFNanoEngine
246
+ */
247
+ typedef enum {
248
+ /** * When temp_store is DEFAULT (0), the compile-time C preprocessor macro SQLITE_TEMP_STORE is used to determine
249
+ where temporary tables and indices are stored. */
250
+ TempStoreModeDefault = 0,
251
+ /** * When temp_store is FILE (1) temporary tables and indices are stored in a file. The temp_store_directory pragma
252
+ can be used to specify the directory containing temporary files when FILE is specified. When the temp_store setting is changed,
253
+ all existing temporary tables, indices, triggers, and views are immediately deleted. */
254
+ TempStoreModeFile,
255
+ /** * When temp_store is MEMORY (2) temporary tables and indices are kept in as if they were pure in-memory databases memory. */
256
+ TempStoreModeMemory,
257
+ } NSFTempStoreMode;
258
+
259
+ /** * Journal mode.
260
+ * These values represent the options used by SQLite to the the journal mode for databases associated with the current database connection.
261
+ @note Note that the journal_mode for an in-memory database is either MEMORY or OFF and can not be changed to a different value. An attempt to change
262
+ the journal_mode of an in-memory database to any setting other than MEMORY or OFF is ignored. Note also that the journal_mode cannot be changed
263
+ while a transaction is active.
264
+ @see NSFNanoEngine
265
+ */
266
+ typedef enum {
267
+ /** * The DELETE journaling mode is the normal behavior. In the DELETE mode, the rollback journal is deleted at the conclusion
268
+ of each transaction. Indeed, the delete operation is the action that causes the transaction to commit. (See the document titled
269
+ Atomic Commit In SQLite for additional detail.) */
270
+ JournalModeDelete = 0,
271
+ /** * The TRUNCATE journaling mode commits transactions by truncating the rollback journal to zero-length instead of deleting it.
272
+ On many systems, truncating a file is much faster than deleting the file since the containing directory does not need to be changed. */
273
+ JournalModeTruncate,
274
+ /** * The PERSIST journaling mode prevents the rollback journal from being deleted at the end of each transaction. Instead, the header
275
+ of the journal is overwritten with zeros. This will prevent other database connections from rolling the journal back. The PERSIST
276
+ journaling mode is useful as an optimization on platforms where deleting or truncating a file is much more expensive than overwriting
277
+ the first block of a file with zeros. */
278
+ JournalModePersist,
279
+ /** * The MEMORY journaling mode stores the rollback journal in volatile RAM. This saves disk I/O but at the expense of database safety
280
+ and integrity. If the application using SQLite crashes in the middle of a transaction when the MEMORY journaling mode is set, then
281
+ the database file will very likely go corrupt. */
282
+ JournalModeMemory,
283
+ /** * The WAL journaling mode uses a write-ahead log instead of a rollback journal to implement transactions. The WAL journaling mode is
284
+ persistent; after being set it stays in effect across multiple database connections and after closing and reopening the database. A database
285
+ in WAL journaling mode can only be accessed by SQLite version 3.7.0 or later. */
286
+ JournalModeWAL,
287
+ /** * The OFF journaling mode disables the rollback journal completely. No rollback journal is ever created and hence there is never a
288
+ rollback journal to delete. The OFF journaling mode disables the atomic commit and rollback capabilities of SQLite. The ROLLBACK command
289
+ no longer works; it behaves in an undefined way. Applications must avoid using the ROLLBACK command when the journal mode is OFF.
290
+ If the application crashes in the middle of a transaction when the OFF journaling mode is set, then the database file will very likely go corrupt. */
291
+ JournalModeOFF
292
+ } NSFJournalModeMode;
293
+
294
+ /** * Memory-backed document store descriptor.
295
+ * This value represents the descriptor used by NanoStore to identify memory-backed document stores. In NSFNanoStore is available via
296
+ * \link NSFNanoStore::filePath - (NSString *)filePath \endlink (assuming the document store was
297
+ * created as a memory-backed document store). In NSFNanoEngine, it's available via its <i>path</i> property.
298
+ @see NSFNanoStore, NSFNanoEngine
299
+ */
300
+ extern NSString * const NSFMemoryDatabase;
301
+
302
+ /** * Temporary store descriptor.
303
+ * This value represents the descriptor used by NanoStore to identify temporary document stores. In NSFNanoStore is available via
304
+ * \link NSFNanoStore::filePath - (NSString *)filePath \endlink (assuming the document store was
305
+ * created as a temporary document store). In NSFNanoEngine, it's available via its \link NSFNanoEngine::path - (NSString *)path \endlink property.
306
+ @see NSFNanoStore, NSFNanoEngine
307
+ */
308
+ extern NSString * const NSFTemporaryDatabase;
309
+
310
+ /** * NanoStore's error code. This value is used by NanoStore when reporting errors.
311
+ */
312
+ extern NSInteger const NSFNanoStoreErrorKey;
313
+
314
+ /** * Exception used when an unexpected parameter has been detected. */
315
+ extern NSString * const NSFUnexpectedParameterException;
316
+ /** * Exception used when a non-confirming NSFNanoObjectProtocol object has been detected. */
317
+ extern NSString * const NSFNonConformingNanoObjectProtocolException;
318
+ /** * Exception used when a NSFNanoObjectProtocol object is not behaving properly (i.e its <i>key</i> property does not return a correct value). */
319
+ extern NSString * const NSFNanoObjectBehaviorException;
320
+ /** * Exception used when a problem occurs while manipulating the document store
321
+ * (adding, updating, deleting, opening a transaction, commit, etc.).
322
+ */
323
+ extern NSString * const NSFNanoStoreUnableToManipulateStoreException;
@@ -0,0 +1,145 @@
1
+ /*
2
+ NSFNanoGlobals.m
3
+ NanoStore
4
+
5
+ Copyright (c) 2010 Webbo, L.L.C. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted
8
+ provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
11
+ and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
+ * Neither the name of Webbo nor the names of its contributors may be used to endorse or promote
15
+ products derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
25
+ */
26
+
27
+ #import "NSFNanoGlobals.h"
28
+
29
+ static BOOL __NSFDebugIsOn = NO;
30
+
31
+ void NSFSetIsDebugOn (BOOL flag)
32
+ {
33
+ __NSFDebugIsOn = flag;
34
+ }
35
+
36
+ BOOL NSFIsDebugOn (void)
37
+ {
38
+ return __NSFDebugIsOn;
39
+ }
40
+
41
+ NSString * NSFStringFromNanoDataType (NSFNanoDatatype aNanoDatatype)
42
+ {
43
+ NSString *value = nil;
44
+
45
+ switch (aNanoDatatype) {
46
+ case NSFNanoTypeUnknown: value = @"UNKNOWN"; break;
47
+ case NSFNanoTypeData: value = @"BLOB"; break;
48
+ case NSFNanoTypeString: value = @"TEXT"; break;
49
+ case NSFNanoTypeDate: value = @"TEXT"; break;
50
+ case NSFNanoTypeNumber: value = @"REAL"; break;
51
+ case NSFNanoTypeRowUID: value = @"INTEGER"; break;
52
+ }
53
+
54
+ return value;
55
+ }
56
+
57
+ NSFNanoDatatype NSFNanoDatatypeFromString (NSString *aNanoDatatype)
58
+ {
59
+ NSFNanoDatatype value = NSFNanoTypeUnknown;
60
+
61
+ if ([aNanoDatatype isEqualToString:@"BLOB"]) value = NSFNanoTypeData;
62
+ else if ([aNanoDatatype isEqualToString:@"TEXT"]) value = NSFNanoTypeString;
63
+ else if ([aNanoDatatype isEqualToString:@"TEXT"]) value = NSFNanoTypeDate;
64
+ else if ([aNanoDatatype isEqualToString:@"REAL"]) value = NSFNanoTypeNumber;
65
+ else if ([aNanoDatatype isEqualToString:@"INTEGER"]) value = NSFNanoTypeRowUID;
66
+
67
+ return value;
68
+ }
69
+
70
+ NSString * NSFStringFromMatchType (NSFMatchType aMatchType)
71
+ {
72
+ NSString *value = nil;
73
+
74
+ switch (aMatchType) {
75
+ case NSFEqualTo: value = @"Equal to"; break;
76
+ case NSFBeginsWith: value = @"Begins with"; break;
77
+ case NSFContains: value = @"Contains"; break;
78
+ case NSFEndsWith: value = @"Ends with"; break;
79
+ case NSFInsensitiveEqualTo: value = @"Equal to (case insensitive)"; break;
80
+ case NSFInsensitiveBeginsWith: value = @"Begins with (case insensitive)"; break;
81
+ case NSFInsensitiveContains: value = @"Contains (case insensitive)"; break;
82
+ case NSFInsensitiveEndsWith: value = @"Ends with (case insensitive)"; break;
83
+ case NSFGreaterThan: value = @"Greater than"; break;
84
+ case NSFLessThan: value = @"Less than"; break;
85
+ }
86
+
87
+ return value;
88
+ }
89
+
90
+ void _NSFLog (NSString *format, ...)
91
+ {
92
+ if (__NSFDebugIsOn) {
93
+ va_list args;
94
+ va_start(args, format);
95
+ NSString *string = [[NSString alloc]initWithFormat:format arguments:args];
96
+ NSLog(@"%@", string);
97
+ va_end(args);
98
+ }
99
+ }
100
+
101
+ NSString * const NSFVersionKey = @"2.0a";
102
+ NSString * const NSFDomainKey = @"com.Webbo.NanoStore.ErrorDomain";
103
+
104
+ NSString * const NSFMemoryDatabase = @":memory:";
105
+ NSString * const NSFTemporaryDatabase = @"";
106
+ NSString * const NSFUnexpectedParameterException = @"NSFUnexpectedParameterException";
107
+ NSString * const NSFNonConformingNanoObjectProtocolException = @"NSFNonConformingNanoObjectProtocolException";
108
+ NSString * const NSFNanoObjectBehaviorException = @"NSFNanoObjectBehaviorException";
109
+ NSString * const NSFNanoStoreUnableToManipulateStoreException = @"NSFNanoStoreUnableToManipulateStoreException";
110
+ NSString * const NSFKeys = @"NSFKeys";
111
+ NSString * const NSFValues = @"NSFValues";
112
+ NSString * const NSFKey = @"NSFKey";
113
+ NSString * const NSFAttribute = @"NSFAttribute";
114
+ NSString * const NSFValue = @"NSFValue";
115
+ NSString * const NSFDatatype = @"NSFDatatype";
116
+ NSString * const NSFCalendarDate = @"NSFCalendarDate";
117
+ NSString * const NSFObjectClass = @"NSFObjectClass";
118
+ NSString * const NSFPlist = @"NSFPlist";
119
+
120
+ #pragma mark -
121
+
122
+ NSString * const NSF_Private_NSFKeys_NSFKey = @"NSFKeys.NSFKey";
123
+ NSString * const NSF_Private_NSFKeys_NSFPlist = @"NSFKeys.NSFPlist";
124
+ NSString * const NSF_Private_NSFValues_NSFKey = @"NSFValues.NSFKey";
125
+ NSString * const NSF_Private_NSFValues_NSFAttribute = @"NSFValues.NSFAttribute";
126
+ NSString * const NSF_Private_NSFValues_NSFValue = @"NSFValues.NSFValue";
127
+ NSString * const NSF_Private_NSFNanoBag_Name = @"NSF_Private_NSFNanoBag_Name";
128
+ NSString * const NSF_Private_NSFNanoBag_NSFKey = @"NSF_Private_NSFNanoBag_NSFKey";
129
+ NSString * const NSF_Private_NSFNanoBag_NSFObjectKeys = @"NSF_Private_NSFNanoBag_NSFObjectKeys";
130
+ NSString * const NSF_Private_ToDeleteTableKey = @"NSF_Private_ToDeleteTableKey";
131
+
132
+ NSString * const NSFRowIDColumnName = @"ROWID";
133
+
134
+ NSInteger const NSF_Private_InvalidParameterDataCodeKey = -10000;
135
+ NSInteger const NSF_Private_MacOSXErrorCodeKey = -10001;
136
+ NSInteger const NSFNanoStoreErrorKey = -10002;
137
+
138
+ #pragma mark Private section
139
+
140
+ NSString * const NSFP_SchemaTable = @"NSFP_SchemaTable";
141
+ NSString * const NSFP_TableIdentifier = @"NSFP_TableIdentifier";
142
+ NSString * const NSFP_ColumnIdentifier = @"NSFP_ColumnIdentifier";
143
+ NSString * const NSFP_DatatypeIdentifier = @"NSFP_DatatypeIdentifier";
144
+
145
+ NSString * const NSFP_FullDatatypeIdentifier = @"NSFP_SchemaTable.NSFP_DatatypeIdentifier";