Kaydet (Commit) 3cdd4964 authored tarafından Caolán McNamara's avatar Caolán McNamara

ditch SISSL using workben code

Change-Id: I9a55180e0a0ef1bc14ce7c84265fb3d5508bd541
üst 3b6ba84a
#*************************************************************************
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
#
# - GNU Lesser General Public License Version 2.1
# - Sun Industry Standards Source License Version 1.1
#
# Sun Microsystems Inc., October, 2000
#
# GNU Lesser General Public License Version 2.1
# =============================================
# Copyright 2000 by Sun Microsystems, Inc.
# 901 San Antonio Road, Palo Alto, CA 94303, USA
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1, as published by the Free Software Foundation.
#
# This 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 this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
#
# Sun Industry Standards Source License Version 1.1
# =================================================
# The contents of this file are subject to the Sun Industry Standards
# Source License Version 1.1 (the "License"); You may not use this file
# except in compliance with the License. You may obtain a copy of the
# License at http://www.openoffice.org/license.html.
#
# Software provided under this License is provided on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
# See the License for the specific provisions governing your rights and
# obligations concerning the Software.
#
# The Initial Developer of the Original Code is: Ralph Thomas
#
# Copyright: 2000 by Sun Microsystems, Inc.
#
# All Rights Reserved.
#
# Contributor(s): Ralph Thomas, Joerg Budischewski
#
#*************************************************************************
from com.sun.star.sdbc import SQLException
import sys
def dumpResultSet( rs ):
meta = rs.getMetaData()
for i in range(1, meta.getColumnCount()+1):
sys.stdout.write(meta.getColumnName( i ) + "\t")
sys.stdout.write( "\n" )
while rs.next():
for i in range( 1, meta.getColumnCount()+1):
sys.stdout.write( rs.getString( i ) + "\t" )
sys.stdout.write( "\n" )
rs.beforeFirst()
def executeIgnoringException( stmt, sql ):
try:
stmt.executeUpdate(sql)
except SQLException:
pass
def cleanGroupsAndUsers( stmt ):
rs = stmt.executeQuery("SELECT groname FROM pg_group WHERE groname LIKE 'pqsdbc_%'" )
stmt2 = stmt.getConnection().createStatement()
while rs.next():
stmt2.executeUpdate("DROP GROUP " + rs.getString(1) )
rs.close()
rs = stmt.executeQuery( "SELECT usename FROM pg_user WHERE usename LIKE 'pqsdbc_%'" )
while rs.next():
stmt2.executeUpdate( "DROP USER " + rs.getString(1) )
def executeDDLs( connection ):
stmt = connection.createStatement()
executeIgnoringException( stmt, "DROP VIEW customer2" )
executeIgnoringException( stmt, "DROP TABLE orderpos" )
executeIgnoringException( stmt, "DROP TABLE ordertab" )
executeIgnoringException( stmt, "DROP TABLE product" )
executeIgnoringException( stmt, "DROP TABLE customer" )
executeIgnoringException( stmt, "DROP TABLE blub" )
executeIgnoringException( stmt, "DROP TABLE foo" )
executeIgnoringException( stmt, "DROP TABLE nooid" )
executeIgnoringException( stmt, "DROP TABLE nooid2" )
cleanGroupsAndUsers( stmt )
executeIgnoringException( stmt, "DROP DOMAIN pqsdbc_short" )
executeIgnoringException( stmt, "DROP DOMAIN pqsdbc_amount" )
executeIgnoringException( stmt, "DROP SCHEMA pqsdbc_test" )
ddls = (
"BEGIN",
"CREATE DOMAIN pqsdbc_short AS int2",
"CREATE DOMAIN pqsdbc_amount AS integer",
"CREATE USER pqsdbc_joe",
"CREATE USER pqsdbc_susy",
"CREATE USER pqsdbc_boss",
"CREATE USER pqsdbc_customer", # technical user (e.g. a webfrontend)
"CREATE GROUP pqsdbc_employees WITH USER pqsdbc_joe,pqsdbc_susy",
"CREATE GROUP pqsdbc_admin WITH USER pqsdbc_susy,pqsdbc_boss",
"CREATE SCHEMA pqsdbc_test",
"CREATE TABLE customer ( "+
"id char(8) UNIQUE PRIMARY KEY, "+
"name text, " +
"dummySerial serial UNIQUE) WITH OIDS",
"COMMENT ON TABLE customer IS 'contains customer attributes'",
"COMMENT ON COLUMN customer.id IS 'unique id'",
"CREATE TABLE product ("+
"id char(8) UNIQUE PRIMARY KEY,"+
"name text,"+
"price numeric(10,2),"+
"image bytea) WITH OIDS",
"CREATE TABLE ordertab ( "+
"id char(8) UNIQUE PRIMARY KEY,"+
"customerid char(8) CONSTRAINT cust REFERENCES customer(id) ON DELETE CASCADE ON UPDATE RESTRICT,"+
"orderdate char(8),"+
"delivered boolean ) WITH OIDS",
"CREATE TABLE orderpos ( "+
"orderid char(8) REFERENCES ordertab(id),"+
"id char(3),"+
"productid char(8) REFERENCES product(id),"+
"amount pqsdbc_amount,"+
"shortamount pqsdbc_short,"+
"PRIMARY KEY (orderid,id)) WITH OIDS",
"CREATE TABLE nooid ("+
"id char(8) UNIQUE PRIMARY KEY,"+
"name text) "+
"WITHOUT OIDS",
"CREATE TABLE nooid2 ("+
"id serial UNIQUE PRIMARY KEY,"+
"name text) "+
"WITHOUT OIDS",
"CREATE VIEW customer2 AS SELECT id,name FROM customer",
"GRANT SELECT ON TABLE customer,product,orderpos,ordertab TO pqsdbc_customer",
"GRANT SELECT ON TABLE product TO GROUP pqsdbc_employees",
"GRANT SELECT,UPDATE, INSERT ON TABLE customer TO GROUP pqsdbc_employees",
"GRANT ALL ON TABLE orderpos,ordertab TO GROUP pqsdbc_employees, GROUP pqsdbc_admin",
"GRANT ALL ON TABLE customer TO GROUP pqsdbc_admin", # the admin is allowed to delete customers
"GRANT ALL ON TABLE product TO pqsdbc_boss", # only the boss may change the product table
"INSERT INTO public.customer VALUES ('C1','John Doe')",
"INSERT INTO \"public\" . \"customer\" VALUES ('C2','Bruce Springsteen')",
"INSERT INTO \"public\".product VALUES ('PZZ2','Pizza Mista',6.95,'\\003foo\\005')",
"INSERT INTO product VALUES ('PZZ5','Pizza Funghi',5.95,'\\001foo\\005')",
"INSERT INTO product VALUES ('PAS1','Lasagne',5.49,NULL)",
"INSERT INTO ordertab VALUES ( '1', 'C2', '20030403','true')",
"INSERT INTO ordertab VALUES ( '2', 'C1', '20030402','false')",
"INSERT INTO orderpos VALUES ( '1','001', 'PZZ2',2,0)",
"INSERT INTO orderpos VALUES ( '1','002', 'PZZ5',3,-1)",
"INSERT INTO orderpos VALUES ( '2','001', 'PAS1',5,1)",
"INSERT INTO orderpos VALUES ( '2','002', 'PZZ2',3,2)",
"COMMIT" )
for i in ddls:
stmt.executeUpdate(i)
connection.getTables() # force refresh of metadata
stmt.close()
#*************************************************************************
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
#
# - GNU Lesser General Public License Version 2.1
# - Sun Industry Standards Source License Version 1.1
#
# Sun Microsystems Inc., October, 2000
#
# GNU Lesser General Public License Version 2.1
# =============================================
# Copyright 2000 by Sun Microsystems, Inc.
# 901 San Antonio Road, Palo Alto, CA 94303, USA
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1, as published by the Free Software Foundation.
#
# This 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 this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
#
# Sun Industry Standards Source License Version 1.1
# =================================================
# The contents of this file are subject to the Sun Industry Standards
# Source License Version 1.1 (the "License"); You may not use this file
# except in compliance with the License. You may obtain a copy of the
# License at http://www.openoffice.org/license.html.
#
# Software provided under this License is provided on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
# See the License for the specific provisions governing your rights and
# obligations concerning the Software.
#
# The Initial Developer of the Original Code is: Joerg Budischewski
#
# Copyright: 2000 by Sun Microsystems, Inc.
#
# All Rights Reserved.
#
# Contributor(s): Joerg Budischewski
#
#
#
#*************************************************************************
import uno
import unohelper
import unittest
import statement
import preparedstatement
import metadata
import sdbcx
import sys
import os
ctx = uno.getComponentContext()
# needed for the tests
unohelper.addComponentsToContext(
ctx,ctx,
("postgresql-sdbc.uno","postgresql-sdbc-impl.uno","typeconverter.uno"),
"com.sun.star.loader.SharedLibrary")
runner = unittest.TextTestRunner(sys.stderr,1,2)
dburl = sys.argv[1] # os.environ['USER'] + "_pqtest"
print "dburl=" + dburl
suite = unittest.TestSuite()
suite.addTest(statement.suite(ctx,dburl))
suite.addTest(preparedstatement.suite(ctx,dburl))
suite.addTest(metadata.suite(ctx,dburl))
suite.addTest(sdbcx.suite(ctx,dburl))
runner.run(suite)
#*************************************************************************
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
#
# - GNU Lesser General Public License Version 2.1
# - Sun Industry Standards Source License Version 1.1
#
# Sun Microsystems Inc., October, 2000
#
# GNU Lesser General Public License Version 2.1
# =============================================
# Copyright 2000 by Sun Microsystems, Inc.
# 901 San Antonio Road, Palo Alto, CA 94303, USA
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1, as published by the Free Software Foundation.
#
# This 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 this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
#
# Sun Industry Standards Source License Version 1.1
# =================================================
# The contents of this file are subject to the Sun Industry Standards
# Source License Version 1.1 (the "License"); You may not use this file
# except in compliance with the License. You may obtain a copy of the
# License at http://www.openoffice.org/license.html.
#
# Software provided under this License is provided on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
# See the License for the specific provisions governing your rights and
# obligations concerning the Software.
#
# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
#
# Copyright: 2000 by Sun Microsystems, Inc.
#
# All Rights Reserved.
#
# Contributor(s): _______________________________________
#
#
#
#*************************************************************************
PRJ=..$/..
PRJNAME=connectivity
TARGET=postgresql-test
LIBTARGET=NO
TARGETTYPE=CUI
ENABLE_EXCEPTIONS=TRUE
# --- Settings -----------------------------------------------------
.INCLUDE : settings.mk
.INCLUDE : sv.mk
# --- Files --------------------------------------------------------
PYFILES = \
$(DLLDEST)$/statement.py \
$(DLLDEST)$/preparedstatement.py \
$(DLLDEST)$/main.py \
$(DLLDEST)$/ddl.py \
$(DLLDEST)$/sdbcx.py \
$(DLLDEST)$/metadata.py
ALL : \
$(PYFILES) \
doc
.INCLUDE : target.mk
$(DLLDEST)$/%.py: %.py
+cp $? $@
.PHONY doc:
@echo "start test with dmake runtest dburl=your-url"
@echo " e.g. dmake runtest dburl=sdbc:postgresql:dbname=pqtest"
@echo " MUST: Create a separate datbases before (here pqtest),"
@echo " (SOME TABLES GET DROPPED)"
runtest : ALL
+cd $(DLLDEST) && python main.py "$(dburl)"
#*************************************************************************
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
#
# - GNU Lesser General Public License Version 2.1
# - Sun Industry Standards Source License Version 1.1
#
# Sun Microsystems Inc., October, 2000
#
# GNU Lesser General Public License Version 2.1
# =============================================
# Copyright 2000 by Sun Microsystems, Inc.
# 901 San Antonio Road, Palo Alto, CA 94303, USA
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1, as published by the Free Software Foundation.
#
# This 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 this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
#
# Sun Industry Standards Source License Version 1.1
# =================================================
# The contents of this file are subject to the Sun Industry Standards
# Source License Version 1.1 (the "License"); You may not use this file
# except in compliance with the License. You may obtain a copy of the
# License at http://www.openoffice.org/license.html.
#
# Software provided under this License is provided on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
# See the License for the specific provisions governing your rights and
# obligations concerning the Software.
#
# The Initial Developer of the Original Code is: Ralph Thomas
#
# Copyright: 2000 by Sun Microsystems, Inc.
#
# All Rights Reserved.
#
# Contributor(s): Ralph Thomas, Joerg Budischewski
#
#*************************************************************************
import unittest
import sys
import ddl
from com.sun.star.sdbc.DataType import SMALLINT, INTEGER, BIGINT , DATE, TIME, TIMESTAMP, NUMERIC
def dumpResultSet( rs , count ):
# for i in range(1, count):
# sys.stdout.write(meta.getColumnName( i ) + "\t")
sys.stdout.write( "\n" )
while rs.next():
for i in range( 1, count+1):
sys.stdout.write( rs.getString( i ) + "\t" )
sys.stdout.write( "\n" )
rs.beforeFirst()
def suite(ctx,dburl):
suite = unittest.TestSuite()
suite.addTest(TestCase("testDatabaseMetaData",ctx,dburl))
suite.addTest(TestCase("testTypeGuess",ctx,dburl))
return suite
class TestCase(unittest.TestCase):
def __init__(self,method,ctx,dburl):
unittest.TestCase.__init__(self,method)
self.ctx = ctx
self.dburl = dburl
def setUp( self ):
self.driver = self.ctx.ServiceManager.createInstanceWithContext(
'org.openoffice.comp.connectivity.pq.Driver.noext' , self.ctx )
self.connection = self.driver.connect( self.dburl, () )
ddl.executeDDLs( self.connection )
def tearDown( self ):
self.connection.close()
def testDatabaseMetaData( self ):
meta = self.connection.getMetaData()
rs = meta.getTables( None, "public", "%", () )
# dumpResultSet( rs, 5)
rs = meta.getColumns( None, "%", "customer", "%" )
# dumpResultSet( rs, 18 )
rs = meta.getPrimaryKeys( None, "public" , "%" )
# dumpResultSet( rs , 6 )
rs = meta.getTablePrivileges( None, "public" , "%" )
# dumpResultSet( rs , 7 )
rs = meta.getColumns( None, "public" , "customer", "%" )
# dumpResultSet( rs , 18 )
rs = meta.getTypeInfo()
# dumpResultSet(rs, 18)
while rs.next():
if rs.getString(1) == "pqsdbc_short":
self.failUnless( rs.getInt(2) == SMALLINT )
break
self.failUnless( not rs.isAfterLast() ) # domain type cannot be found
rs = meta.getIndexInfo( None, "public" , "customer", False, False )
# dumpResultSet( rs, 13 )
def testTypeGuess( self ):
stmt = self.connection.createStatement()
rs = stmt.executeQuery( "SELECT sum(amount) FROM orderpos" )
meta = rs.getMetaData()
self.failUnless( meta.getColumnType(1) == BIGINT )
stmt = self.connection.createStatement()
rs = stmt.executeQuery( "SELECT sum(price) FROM product" )
meta = rs.getMetaData()
self.failUnless( meta.getColumnType(1) == NUMERIC )
rs = stmt.executeQuery( "SELECT max(ttime) FROM firsttable" )
meta = rs.getMetaData()
self.failUnless( meta.getColumnType(1) == TIME )
rs = stmt.executeQuery( "SELECT max(tdate) FROM firsttable" )
meta = rs.getMetaData()
self.failUnless( meta.getColumnType(1) == DATE )
rs = stmt.executeQuery( "SELECT max(ttimestamp) FROM firsttable" )
meta = rs.getMetaData()
self.failUnless( meta.getColumnType(1) == TIMESTAMP )
# rs.next()
# print rs.getString( 1 )
#*************************************************************************
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
#
# - GNU Lesser General Public License Version 2.1
# - Sun Industry Standards Source License Version 1.1
#
# Sun Microsystems Inc., October, 2000
#
# GNU Lesser General Public License Version 2.1
# =============================================
# Copyright 2000 by Sun Microsystems, Inc.
# 901 San Antonio Road, Palo Alto, CA 94303, USA
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1, as published by the Free Software Foundation.
#
# This 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 this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
#
# Sun Industry Standards Source License Version 1.1
# =================================================
# The contents of this file are subject to the Sun Industry Standards
# Source License Version 1.1 (the "License"); You may not use this file
# except in compliance with the License. You may obtain a copy of the
# License at http://www.openoffice.org/license.html.
#
# Software provided under this License is provided on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
# See the License for the specific provisions governing your rights and
# obligations concerning the Software.
#
# The Initial Developer of the Original Code is: Ralph Thomas
#
# Copyright: 2000 by Sun Microsystems, Inc.
#
# All Rights Reserved.
#
# Contributor(s): Ralph Thomas, Joerg Budischewski
#
#*************************************************************************
import unittest
import sys
import ddl
from uno import ByteSequence
from com.sun.star.sdbc import SQLException
from com.sun.star.sdbc.ResultSetConcurrency import UPDATABLE
from com.sun.star.sdbc.DataType import NUMERIC,VARCHAR
def suite(ctx,dburl):
suite = unittest.TestSuite()
suite.addTest(TestCase("testQuery",ctx,dburl))
suite.addTest(TestCase("testGeneratedResultSet",ctx,dburl))
suite.addTest(TestCase("testUpdateableResultSet",ctx,dburl))
suite.addTest(TestCase("testQuoteQuote",ctx,dburl))
return suite
def realEquals( a,b,eps ):
val = a - b
if val < 0:
val = -1. * val
return val < eps
class TestCase(unittest.TestCase):
def __init__(self,method,ctx,dburl):
unittest.TestCase.__init__(self,method)
self.ctx = ctx
self.dburl = dburl
def setUp(self):
self.driver = self.ctx.ServiceManager.createInstanceWithContext(
'org.openoffice.comp.connectivity.pq.Driver.noext', self.ctx )
self.connection = self.driver.connect( self.dburl, () )
ddl.executeDDLs( self.connection )
def testDown( self ):
self.connection.close()
def testQuery( self ):
stmts = "SELECT product.id FROM product WHERE product.price > :lowprice AND product.price < :upprice", \
"SELECT product.id FROM product WHERE product.price > ? AND product.price < ?" , \
"SELECT \"product\".\"id\" FROM product WHERE \"product\".\"price\" > :lowprice AND \"product\".\"price\" < :upprice"
for stmt in stmts:
prepstmt = self.connection.prepareStatement( stmt )
prepstmt.setDouble( 1, 5.80 )
prepstmt.setObjectWithInfo( 2, 7. , NUMERIC, 2)
prepstmt.setObjectWithInfo( 2, "7.0000", NUMERIC, 2 )
rs = prepstmt.executeQuery( )
self.failUnless( rs.getMetaData().getColumnCount() == 1 )
self.failUnless( rs.getMetaData().getColumnName(1) == "id")
self.failUnless( prepstmt.getMetaData().getColumnCount() == 1 )
self.failUnless( prepstmt.getMetaData().getColumnName(1) == "id" )
self.failUnless( rs.next() )
self.failUnless( rs.getString( 1 ).strip() == "PZZ2" )
self.failUnless( rs.next() )
self.failUnless( rs.getString( 1 ).strip() == "PZZ5" )
self.failUnless( rs.isLast() )
prepstmt = self.connection.prepareStatement(
"SELECT name FROM product WHERE id = ?" )
prepstmt.setString( 1, 'PZZ2' )
rs = prepstmt.executeQuery()
self.failUnless( rs.next() )
self.failUnless( rs.getString( 1 ) == "Pizza Mista" )
self.failUnless( rs.isLast() )
prepstmt = self.connection.prepareStatement(
"SELECT name FROM product WHERE image = ?" )
prepstmt.setBytes( 1, ByteSequence( "\001foo\005" ) )
rs = prepstmt.executeQuery()
self.failUnless( rs.next() )
self.failUnless( rs.getString( 1 ) == "Pizza Funghi" )
self.failUnless( rs.isLast() )
prepstmt = self.connection.prepareStatement(
"SELECT * FROM ordertab WHERE delivered = ?" )
prepstmt.setBoolean( 1 , False )
rs = prepstmt.executeQuery()
self.failUnless( rs.next() )
self.failUnless( rs.getString( 1 ).strip() == "2" )
self.failUnless( rs.isLast() )
stmt = self.connection.createStatement()
rs = stmt.executeQuery( "SELECT * FROM \"public\".\"customer\"" )
stmt.executeUpdate( "DELETE FROM product where id='PAS5'" )
prepstmt =self.connection.prepareStatement(
"INSERT INTO product VALUES(?,'Ravioli',?,NULL)" );
prepstmt.setObjectWithInfo( 1, "PAS5" ,VARCHAR,0)
prepstmt.setObjectWithInfo( 2, "9.223" ,NUMERIC,2)
prepstmt.executeUpdate()
rs= stmt.executeQuery( "SELECT price FROM product WHERE id = 'PAS5'" )
self.failUnless( rs.next() )
self.failUnless( rs.getString( 1 ).strip() == "9.22" )
stmt.executeUpdate( "DELETE FROM product where id='PAS5'" )
prepstmt =self.connection.prepareStatement(
"INSERT INTO product VALUES('PAS5','Ravioli',?,NULL)" );
prepstmt.setObjectWithInfo( 1, 9.223,NUMERIC,2 )
prepstmt.executeUpdate()
rs= stmt.executeQuery( "SELECT price FROM product WHERE id = 'PAS5'" )
self.failUnless( rs.next() )
self.failUnless( rs.getString( 1 ).strip() == "9.22" )
def testGeneratedResultSet( self ):
prepstmt = self.connection.prepareStatement(
"INSERT INTO customer VALUES( ?, ? )" )
prepstmt.setString( 1, "C3" )
prepstmt.setString( 2, "Norah Jones" )
prepstmt.executeUpdate()
rs = prepstmt.getGeneratedValues()
self.failUnless( rs.next() )
self.failUnless( rs.getInt( 3 ) == 3 )
prepstmt = self.connection.prepareStatement(
"INSERT INTO public.nooid (id,name) VALUES( ?, ? )" )
prepstmt.setString( 1, "C3" )
prepstmt.setString( 2, "Norah Jones" )
prepstmt.executeUpdate()
rs = prepstmt.getGeneratedValues()
self.failUnless( rs.next() )
self.failUnless( rs.getString(1).rstrip() == "C3" )
prepstmt = self.connection.prepareStatement(
"INSERT INTO public.nooid2 (name) VALUES( ? )" )
prepstmt.setString( 1, "Norah Jones" )
prepstmt.executeUpdate()
rs = prepstmt.getGeneratedValues()
self.failUnless( rs )
self.failUnless( rs.next() )
self.failUnless( rs.getString(2) == "Norah Jones" )
self.failUnless( rs.getString(1) == "1" )
def testUpdateableResultSet( self ):
stmt = self.connection.createStatement()
stmt.ResultSetConcurrency = UPDATABLE
rs = stmt.executeQuery( "SELECT * FROM orderpos" )
# ddl.dumpResultSet( rs )
rs.next()
rs.deleteRow()
rs.next()
rs.updateInt( 4 , 32 )
rs.updateRow()
rs.moveToInsertRow()
rs.updateString( 1 , '2' )
rs.updateString( 2, '003' )
rs.updateString( 3, 'PZZ5' )
rs.updateInt( 4, 22 )
rs.insertRow()
rs = stmt.executeQuery( "SELECT * FROM orderpos" )
rs = stmt.executeQuery( "SELECT * FROM \"public\".\"orderpos\"" )
# ddl.dumpResultSet( rs )
def testQuoteQuote( self ):
stmt = self.connection.prepareStatement( "select 'foo''l'" )
rs = stmt.executeQuery()
self.failUnless( rs )
self.failUnless( rs.next() )
self.failUnless( rs.getString(1) == "foo'l" )
stmt = self.connection.prepareStatement( "select 'foo''''l'" )
rs = stmt.executeQuery()
self.failUnless( rs )
self.failUnless( rs.next() )
self.failUnless( rs.getString(1) == "foo''l" )
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment