1"====================================================================== 2| 3| SQLite bindings, bridge to the C library 4| 5| 6 ======================================================================" 7 8 9"====================================================================== 10| 11| Copyright 2007, 2008 Free Software Foundation, Inc. 12| Written by Daniele Sciascia 13| 14| This file is part of the GNU Smalltalk class library. 15| 16| The GNU Smalltalk class library is free software; you can redistribute it 17| and/or modify it under the terms of the GNU Lesser General Public License 18| as published by the Free Software Foundation; either version 2.1, or (at 19| your option) any later version. 20| 21| The GNU Smalltalk class library is distributed in the hope that it will be 22| useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 23| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 24| General Public License for more details. 25| 26| You should have received a copy of the GNU Lesser General Public License 27| along with the GNU Smalltalk class library; see the file COPYING.LIB. 28| If not, write to the Free Software Foundation, 59 Temple Place - Suite 29| 330, Boston, MA 02110-1301, USA. 30| 31 ====================================================================== 32" 33 34 35Object subclass: SQLite3Handle [ 36 | db | 37 38 errorMessage [ 39 <cCall: 'gst_sqlite3_error_message' returing: #string args: #(#self)> 40 ] 41 42 checkError: aBoolean [ 43 aBoolean ifFalse: [ self error: self errorMessage ] 44 ] 45 46 changes [ 47 <category: 'sqlite3 wrapper'> 48 <cCall: 'gst_sqlite3_changes' returning: #int args: #(#self)> 49 ] 50] 51 52SQLite3Handle subclass: SQLite3DBHandle [ 53 SQLite3DBHandle class >> open: dbname [ 54 | result rc | 55 result := self new. 56 rc := result open: dbname. 57 rc = 0 ifFalse: [ self error: 'error: ', rc printString ]. 58 ^result 59 ] 60 61 open: dbname [ 62 <cCall: 'gst_sqlite3_open' returning: #int args: #(#self #string)> 63 ] 64 65 close [ 66 <cCall: 'gst_sqlite3_close' returning: #int args: #(#self)> 67 ] 68 69 prepare: aSQLQuery [ 70 ^SQLite3StmtHandle forQuery: aSQLQuery onHandle: db 71 ] 72] 73 74SQLite3Handle subclass: SQLite3StmtHandle [ 75 | stmt colCount colTypes colNames returnedRow | 76 77 SQLite3StmtHandle class >> forQuery: aSQLQuery onHandle: aDbHandle [ 78 | result rc | 79 result := self new db: aDbHandle. 80 rc := result prepare: aSQLQuery. 81 rc = 0 ifFalse: [ self error: 'error: ', rc printString ]. 82 ^result 83 ] 84 85 db [ 86 <category: 'private'> 87 ^db 88 ] 89 90 db: aDbHandle [ 91 <category: 'private'> 92 db := aDbHandle 93 ] 94 95 finalize [ 96 <category: 'private'> 97 <cCall: 'gst_sqlite3_finalize' returning: #int args: #(#self)> 98 ] 99 100 prepare: aSQLQuery [ 101 <category: 'sqlite3 wrapper'> 102 <cCall: 'gst_sqlite3_prepare' returning: #int args: #(#self #string)> 103 ] 104 105 exec [ 106 <category: 'sqlite3 wrapper'> 107 <cCall: 'gst_sqlite3_exec' returning: #int args: #(#self)> 108 ] 109 110 bindingAt: index put: value [ 111 <category: 'sqlite3 wrapper'> 112 <cCall: 'gst_sqlite3_bind' returning: #int args: #(#self #smalltalk #smalltalk)> 113 ] 114 115 clearBindings [ 116 <category: 'sqlite3 wrapper'> 117 <cCall: 'gst_sqlite3_clear_bindings' returning: #int args: #(#self)> 118 ] 119 120 reset [ 121 <category: 'sqlite3 wrapper'> 122 <cCall: 'gst_sqlite3_reset' returning: #int args: #(#self)> 123 ] 124 125 colCount [ 126 <category: 'accessing'> 127 ^colCount 128 ] 129 130 colTypes [ 131 <category: 'accessing'> 132 ^colTypes 133 ] 134 135 colNames [ 136 <category: 'accessing'> 137 ^colNames 138 ] 139 140 returnedRow [ 141 <category: 'accessing'> 142 ^returnedRow 143 ] 144] 145