'From Squeak3.8 of ''5 May 2005'' [latest update: #6665] on 24 November 2005 at 8:48:15 am'! Object subclass: #SQLiteConnection instanceVariableNames: 'reference fileName' classVariableNames: '' poolDictionaries: '' category: 'SQLite-Public'! SQLiteConnection class instanceVariableNames: 'registry'! ExternalStructure subclass: #SqliteError instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'SQLite-Support'! ExternalLibrary subclass: #SqliteLibrary instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'SQLite-Support'! SqliteLibrary class instanceVariableNames: 'default'! ExternalStructure subclass: #SqliteReference instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'SQLite-Support'! Object subclass: #SqliteResult instanceVariableNames: 'buffer rows columns columnNames index' classVariableNames: '' poolDictionaries: '' category: 'SQLite-Support'! ExternalStructure subclass: #SqliteResultBuffer instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'SQLite-Support'! !SQLiteConnection methodsFor: 'finalization' stamp: 'ab 2/22/2003 23:15'! actAsExecutor super actAsExecutor. fileName _ nil! ! !SQLiteConnection methodsFor: 'finalization' stamp: 'ab 2/22/2003 23:15'! finalize self close.! ! !SQLiteConnection methodsFor: 'finalization' stamp: 'ab 2/22/2003 22:31'! register self class registry add: self! ! !SQLiteConnection methodsFor: 'finalization' stamp: 'ab 2/22/2003 22:32'! unregister self class registry remove: self ifAbsent: []! ! !SQLiteConnection methodsFor: 'public' stamp: 'ab 1/31/2003 16:20'! changedRows ^ self isOpen ifTrue: [SqliteLibrary default changedRows: reference] ifFalse: [0] ! ! !SQLiteConnection methodsFor: 'public' stamp: 'ab 1/29/2003 16:37'! executeQuery: aString ^ self withResultForQuery: aString do: [:result | Array streamContents: [:s | result do: [:row | s nextPut: row]]]! ! !SQLiteConnection methodsFor: 'public' stamp: 'ab 12/16/2002 00:27'! fileName ^ fileName! ! !SQLiteConnection methodsFor: 'public' stamp: 'ab 12/16/2002 00:34'! lastInsertId ^ self isOpen ifTrue: [SqliteLibrary default lastInsertId: reference] ifFalse: [0] ! ! !SQLiteConnection methodsFor: 'public' stamp: 'ab 2/22/2003 22:38'! withResultForQuery: aString do: aBlock |result| self isOpen ifFalse: [self open]. result _ SqliteLibrary default resultForQuery: aString on: reference. ^ [aBlock value: result] ensure: [result free]! ! !SQLiteConnection methodsFor: 'private' stamp: 'ab 2/22/2003 23:16'! close self unregister. self isOpen ifTrue: [SqliteLibrary default close: reference]. reference _ nil. ! ! !SQLiteConnection methodsFor: 'private' stamp: 'ab 12/16/2002 00:27'! fileName: aString fileName _ aString! ! !SQLiteConnection methodsFor: 'private' stamp: 'ab 12/16/2002 00:28'! isOpen ^ reference notNil and: [reference getHandle anySatisfy: [:i | i > 0]]! ! !SQLiteConnection methodsFor: 'private' stamp: 'ab 2/22/2003 23:15'! open reference _ SqliteLibrary default open: fileName. self register. ! ! !SQLiteConnection class methodsFor: 'as yet unclassified' stamp: 'ab 12/16/2002 00:27'! fileNamed: aString ^ self new fileName: aString! ! !SQLiteConnection class methodsFor: 'as yet unclassified' stamp: 'ab 2/22/2003 22:31'! registry ^ registry ifNil: [registry _ WeakRegistry new]! ! !SqliteError methodsFor: 'accessing' stamp: 'cf 11/18/2005 11:04'! value "This method was automatically generated" ^ExternalData fromHandle: (handle pointerAt: 1) type: ExternalType char asPointerType! ! !SqliteError methodsFor: 'accessing' stamp: 'cf 11/18/2005 11:04'! value: anObject "This method was automatically generated" handle pointerAt: 1 put: anObject getHandle.! ! !SqliteError class methodsFor: 'as yet unclassified' stamp: 'ab 12/15/2002 21:55'! fields "self defineFields" ^ #((value 'char*'))! ! !SqliteError class methodsFor: 'as yet unclassified' stamp: 'ab 12/15/2002 22:17'! initialize self defineFields! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'cf 11/23/2005 15:31'! apiChanges: sqlite "int sqlite_changes(sqlite*)" ^ self externalCallFailed ! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'cf 11/23/2005 15:15'! apiClose: sqlite "int sqlite3_close(sqlite3*)" ^ self externalCallFailed ! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'cf 11/23/2005 15:52'! apiErrorMessage: anSqlite "const char *sqlite3_errmsg(sqlite3*)" ^ self externalCallFailed ! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'cf 11/23/2005 15:32'! apiFreeTable: buffer "void sqlite3_free_table(char **result)" ^ self externalCallFailed! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'cf 11/23/2005 15:34'! apiGetTable: anSqlite sql: sql buffer: result rows: nRows columns: nColumns error: errBuffer "int sqlite3_get_table( sqlite*, char *sql, char ***result, int *nrow, int *ncolumn, char **errmsg )" ^ self externalCallFailed ! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'cf 11/23/2005 15:35'! apiLastInsertId: sqlite "long long int sqlite3_last_insert_rowid(sqlite3*)" ^ self externalCallFailed ! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'cf 11/22/2005 21:59'! apiOpen: dbName sqlite: sqlite "int sqlite3_open(const char*, sqlite3**);" ^ self externalCallFailed! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'ab 1/31/2003 16:20'! changedRows: anSqliteRef ^ self apiChanges: anSqliteRef! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'cf 11/23/2005 16:16'! checkErrorInteger: anError |message| (anError = 0) ifTrue: [^self]. "Get the errmsg" message := 'Result Code: ' + anError asString. self error: message! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'cf 11/23/2005 15:36'! checkError: anError |message| (anError getHandle allSatisfy: [:i | i = 0]) ifTrue: [^ self]. message := anError value fromCString. anError free. self error: message ! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'cf 11/23/2005 15:29'! close: anSqliteRef | err | err _ self apiClose: anSqliteRef. self checkErrorInteger: err.! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'ab 12/16/2002 01:30'! freeResultBuffer: aResultBuffer self apiFreeTable: aResultBuffer! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'ab 12/16/2002 00:23'! lastInsertId: anSqliteRef ^ self apiLastInsertId: anSqliteRef! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'cf 11/23/2005 15:22'! open: aString |err ref| ref := SqliteReference new. err := self apiOpen: aString sqlite: ref. self checkErrorInteger: err. ^ ref! ! !SqliteLibrary methodsFor: 'as yet unclassified' stamp: 'ab 1/29/2003 15:25'! resultForQuery: aString on: sqliteRef |nrows ncols buffer err| nrows _ WordArray new: 1. ncols _ WordArray new: 1. err _ SqliteError new. buffer _ SqliteResultBuffer new. self apiGetTable: sqliteRef sql: aString buffer: buffer rows: nrows columns: ncols error: err. self checkError: err. ^ SqliteResult buffer: buffer rows: nrows first columns: ncols first! ! !SqliteLibrary class methodsFor: 'as yet unclassified' stamp: 'ab 12/15/2002 21:39'! default ^ default ifNil: [default _ super new]! ! !SqliteLibrary class methodsFor: 'as yet unclassified' stamp: 'cf 11/23/2005 15:59'! moduleName "Was: ^ 'sqlite'" ^ 'libsqlite3.framework'! ! !SqliteReference methodsFor: 'accessing' stamp: 'cf 11/22/2005 21:58'! value "This method was automatically generated" ^ExternalData fromHandle: (handle pointerAt: 1) type: ExternalType void asPointerType! ! !SqliteReference methodsFor: 'accessing' stamp: 'cf 11/22/2005 21:58'! value: anObject "This method was automatically generated" handle pointerAt: 1 put: anObject getHandle.! ! !SqliteReference class methodsFor: 'as yet unclassified' stamp: 'cf 11/22/2005 21:38'! fields "self defineFields" ^ #((value 'void*'))! ! !SqliteReference class methodsFor: 'as yet unclassified' stamp: 'cf 11/22/2005 21:58'! initialize "SqliteReference initialize" self defineFields! ! !SqliteResult methodsFor: 'public' stamp: 'ab 12/16/2002 01:58'! atEnd ^ index > (rows + 1 * columns)! ! !SqliteResult methodsFor: 'public' stamp: 'ab 1/29/2003 16:06'! columnNames ^ columnNames! ! !SqliteResult methodsFor: 'public' stamp: 'ab 12/16/2002 01:56'! do: aBlock self reset. rows timesRepeat: [aBlock value: self nextRow]. ! ! !SqliteResult methodsFor: 'public' stamp: 'ab 12/16/2002 01:31'! free SqliteLibrary default freeResultBuffer: buffer. buffer _ nil.! ! !SqliteResult methodsFor: 'public' stamp: 'ab 12/16/2002 01:58'! nextKeysAndValuesDo: aBlock self atEnd ifTrue: [self error: 'Trying to read past end of results']. columnNames do: [:ea | aBlock value: ea value: self nextString]! ! !SqliteResult methodsFor: 'public' stamp: 'ab 12/16/2002 01:38'! nextRow |row| row _ Dictionary new. self nextKeysAndValuesDo: [:k :v | row at: k put: v]. ^ row! ! !SqliteResult methodsFor: 'public' stamp: 'ab 1/29/2003 16:34'! nextValues ^ columnNames collect: [:ea | self nextString]! ! !SqliteResult methodsFor: 'public' stamp: 'ab 12/16/2002 01:57'! reset index _ 1. self readColumns.! ! !SqliteResult methodsFor: 'as yet unclassified' stamp: 'ab 12/16/2002 17:39'! currentAddress |bytes base current| bytes _ buffer value getHandle asByteArrayPointer. base _ bytes unsignedLongAt: 1. current _ base + (index - 1 * 4). bytes unsignedLongAt: 1 put: current. ^ bytes asExternalPointer ! ! !SqliteResult methodsFor: 'as yet unclassified' stamp: 'ab 12/16/2002 01:45'! nextString |str| buffer ifNil: [self error: 'Result has been freed']. str _ self readString. index _ index + 1. ^ str! ! !SqliteResult methodsFor: 'as yet unclassified' stamp: 'ab 12/16/2002 01:57'! readColumns columnNames _ OrderedCollection new. columns timesRepeat: [columnNames add: self nextString]! ! !SqliteResult methodsFor: 'as yet unclassified' stamp: 'ab 12/16/2002 01:47'! readString ^ self readStringAtAddress: (self currentAddress)! ! !SqliteResult methodsFor: 'as yet unclassified' stamp: 'ab 12/16/2002 01:46'! readStringAtAddress: anAddress |deref i char| deref _ anAddress pointerAt: 1. (deref allSatisfy: [:ea | ea = 0]) ifTrue: [^ nil]. ^ String streamContents: [:stream | i _ 1. [(char _ deref unsignedCharAt: i) asciiValue = 0] whileFalse: [stream nextPut: char isoToSqueak. i _ i + 1]]! ! !SqliteResult methodsFor: 'as yet unclassified' stamp: 'ab 12/16/2002 02:00'! setBuffer: aResultBuffer rows: nRows columns: nColumns buffer _ aResultBuffer. rows _ nRows. columns _ nColumns. self reset.! ! !SqliteResult class methodsFor: 'as yet unclassified' stamp: 'ab 12/16/2002 01:41'! buffer: aResultBuffer rows: nRows columns: nColumns ^ self new setBuffer: aResultBuffer rows: nRows columns: nColumns! ! !SqliteResultBuffer methodsFor: 'accessing' stamp: 'cf 11/18/2005 11:04'! value "This method was automatically generated" ^ExternalData fromHandle: (handle pointerAt: 1) type: ExternalType void asPointerType! ! !SqliteResultBuffer methodsFor: 'accessing' stamp: 'cf 11/18/2005 11:04'! value: anObject "This method was automatically generated" handle pointerAt: 1 put: anObject getHandle.! ! !SqliteResultBuffer class methodsFor: 'as yet unclassified' stamp: 'ab 12/16/2002 00:35'! fields "self defineFields" ^ #((value 'void*'))! ! !SqliteResultBuffer class methodsFor: 'as yet unclassified' stamp: 'ab 1/14/2003 15:28'! initialize self defineFields! ! SqliteResultBuffer initialize! SqliteReference initialize! !SqliteReference reorganize! ('accessing' value value:) ! SqliteLibrary removeSelector: #apiOpen:mode:error:! SqliteLibrary removeSelector: #apiOpen:sqlite3:! SqliteError initialize!