1"===================================================================== 2| 3| Generic database interface - Statement class 4| 5| 6 ======================================================================" 7 8"====================================================================== 9| 10| Copyright 2006 Mike Anderson 11| Copyright 2007, 2008, 2011 Free Software Foundation, Inc. 12| 13| Written by Mike Anderson 14| 15| This file is part of the GNU Smalltalk class library. 16| 17| The GNU Smalltalk class library is free software; you can redistribute it 18| and/or modify it under the terms of the GNU Lesser General Public License 19| as published by the Free Software Foundation; either version 2.1, or (at 20| your option) any later version. 21| 22| The GNU Smalltalk class library is distributed in the hope that it will be 23| useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 24| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 25| General Public License for more details. 26| 27| You should have received a copy of the GNU Lesser General Public License 28| along with the GNU Smalltalk class library; see the file COPYING.LIB. 29| If not, write to the Free Software Foundation, 59 Temple Place - Suite 30| 330, Boston, MA 02110-1301, USA. 31| 32 ====================================================================== 33" 34 35 36 37Object subclass: Statement [ 38 | connection | 39 40 <category: 'DBI-Framework'> 41 <comment: 'I represent a prepared statement.'> 42 43 Statement class >> on: aConnection [ 44 "Return a new statement for this connection." 45 46 <category: 'instance creation'> 47 ^self new 48 connection: aConnection; 49 yourself 50 ] 51 52 Statement class >> getCommand: queryString [ 53 | readStream writeStream aCharacter | 54 writeStream := WriteStream on: String new. 55 readStream := ReadStream on: queryString. 56 readStream skipSeparators. 57 [readStream atEnd 58 or: [aCharacter := readStream next. aCharacter isSeparator]] 59 whileFalse: [writeStream nextPut: aCharacter asUppercase]. 60 ^writeStream contents 61 ] 62 63 connection [ 64 "Return the connection for which the statement was prepared." 65 66 <category: 'private'> 67 ^connection 68 ] 69 70 connection: aConnection [ 71 "Associate the statement to the given Connection." 72 73 <category: 'private'> 74 connection := aConnection 75 ] 76 77 execute [ 78 "Execute with no parameters (abstract)." 79 80 <category: 'querying'> 81 self subclassResponsibility 82 ] 83 84 executeWith: aParameter [ 85 "Execute with one parameters." 86 87 <category: 'querying'> 88 ^self executeWithAll: {aParameter} 89 ] 90 91 executeWith: aParam1 with: aParam2 [ 92 "Execute with two parameters." 93 94 <category: 'querying'> 95 ^self executeWithAll: 96 {aParam1. 97 aParam2} 98 ] 99 100 executeWith: aParam1 with: aParam2 with: aParam3 [ 101 "Execute with three parameters." 102 103 <category: 'querying'> 104 ^self executeWithAll: 105 {aParam1. 106 aParam2. 107 aParam3} 108 ] 109 110 executeWithAll: aParams [ 111 "Execute taking parameters from the Collection aParams (abstract)." 112 113 <category: 'querying'> 114 self subclassResponsibility 115 ] 116] 117 118