>From cdafb34a2518651763b3c213bc126a41ebb24edd Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 8 Apr 2011 11:09:58 +0200 Subject: [PATCH 2/4] dbd-postgres: Prepare to have prepared statements in postgres Like the SQLite driver implement Connection>>#do: and #select: on top of the Connection>>#prepare: method. There is no functional change right no. --- packages/dbd-postgresql/ChangeLog | 4 ++ packages/dbd-postgresql/Connection.st | 24 ++++------ packages/dbd-postgresql/Makefile.frag | 2 +- packages/dbd-postgresql/Statement.st | 79 +++++++++++++++++++++++++++++++++ packages/dbd-postgresql/package.xml | 1 + 5 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 packages/dbd-postgresql/Statement.st diff --git a/packages/dbd-postgresql/ChangeLog b/packages/dbd-postgresql/ChangeLog index 18a1e97..ea768b5 100644 --- a/packages/dbd-postgresql/ChangeLog +++ b/packages/dbd-postgresql/ChangeLog @@ -1,3 +1,7 @@ +2011-04-08 Holger Hans Peter Freyther + + * Statement.st: New. + 2011-01-26 Stefan Schmiedl * Table.st: Take current domain into account. diff --git a/packages/dbd-postgresql/Connection.st b/packages/dbd-postgresql/Connection.st index 25694b8..f23d3f2 100644 --- a/packages/dbd-postgresql/Connection.st +++ b/packages/dbd-postgresql/Connection.st @@ -113,24 +113,20 @@ Connection subclass: PGConnection [ ] do: aSQLQuery [ - - ^(PGResultSet new: (handle exec: aSQLQuery)) - checkStatusForDo; - yourself + + ^(self prepare: aSQLQuery) execute ] - prepare: aSQLQuery [ - "FIXME" - - - self notYetImplemented + select: aSQLQuery [ + + ^(self prepare: aSQLQuery) execute ] - select: aSQLQuery [ - - ^(PGResultSet new: (handle exec: aSQLQuery)) - checkStatusForSelect; - yourself + prepare: aSQLQuery [ + + ^(PGStatement on: self) + dbHandle: handle; + queryString: aSQLQuery. ] close [ diff --git a/packages/dbd-postgresql/Makefile.frag b/packages/dbd-postgresql/Makefile.frag index 6991183..3479b44 100644 --- a/packages/dbd-postgresql/Makefile.frag +++ b/packages/dbd-postgresql/Makefile.frag @@ -1,5 +1,5 @@ DBD-PostgreSQL_FILES = \ -packages/dbd-postgresql/Connection.st packages/dbd-postgresql/ResultSet.st packages/dbd-postgresql/Row.st packages/dbd-postgresql/ColumnInfo.st packages/dbd-postgresql/Table.st packages/dbd-postgresql/TableColumnInfo.st packages/dbd-postgresql/FieldConverter.st +packages/dbd-postgresql/Connection.st packages/dbd-postgresql/ResultSet.st packages/dbd-postgresql/Row.st packages/dbd-postgresql/ColumnInfo.st packages/dbd-postgresql/Statement.st packages/dbd-postgresql/Table.st packages/dbd-postgresql/TableColumnInfo.st packages/dbd-postgresql/FieldConverter.st $(DBD-PostgreSQL_FILES): $(srcdir)/packages/dbd-postgresql/stamp-classes: $(DBD-PostgreSQL_FILES) touch $(srcdir)/packages/dbd-postgresql/stamp-classes diff --git a/packages/dbd-postgresql/Statement.st b/packages/dbd-postgresql/Statement.st new file mode 100644 index 0000000..c9cfaa7 --- /dev/null +++ b/packages/dbd-postgresql/Statement.st @@ -0,0 +1,79 @@ +"====================================================================== +| +| PostgreSQL bindings, Statement class +| +| + ======================================================================" + + +"====================================================================== +| +| Copyright 2011 Free Software Foundation, Inc. +| Written by Holger Hans Peter Freyther +| +| This file is part of the GNU Smalltalk class library. +| +| The GNU Smalltalk class library is free software; you can redistribute it +| and/or modify it under the terms of the GNU Lesser General Public License +| as published by the Free Software Foundation; either version 2.1, or (at +| your option) any later version. +| +| The GNU Smalltalk class library is distributed in the hope that it will be +| useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser +| General Public License for more details. +| +| You should have received a copy of the GNU Lesser General Public License +| along with the GNU Smalltalk class library; see the file COPYING.LIB. +| If not, write to the Free Software Foundation, 59 Temple Place - Suite +| 330, Boston, MA 02110-1301, USA. +| + ====================================================================== +" + + +Statement subclass: PGStatement [ + | dbHandle queryString isSelect | + + + + + SelectQueries := #('EXPLAIN' 'SELECT') asSet. + + dbHandle: aHandle [ + + dbHandle := aHandle. + ] + + queryString [ + + ^queryString + ] + + queryString: aSQLQuery [ + + queryString := aSQLQuery. + ] + + isSelect [ + + isSelect isNil + ifTrue: [isSelect := SelectQueries includes: (self class getCommand: queryString)]. + ^isSelect + ] + + execute [ + + | res | + res := PGResultSet new: (dbHandle exec: queryString). + self isSelect + ifTrue: [res checkStatusForSelect] + ifFalse: [res checkStatusForDo]. + ^ res + ] + + executeWithAll: aParams [ + self notYetImplemented + ] +] diff --git a/packages/dbd-postgresql/package.xml b/packages/dbd-postgresql/package.xml index b1a336e..36d6a29 100644 --- a/packages/dbd-postgresql/package.xml +++ b/packages/dbd-postgresql/package.xml @@ -8,6 +8,7 @@ ResultSet.st Row.st ColumnInfo.st + Statement.st Table.st TableColumnInfo.st FieldConverter.st -- 1.7.4