GAPreparedStamentTest

GADriverTest subclass: #'GAPreparedStamentTest' 

Overview

Please comment me using the following template inspired by Class Responsibility Collaborator (CRC) design:

For the Class part: State the name of the class with one line description: For example, I'm xxx the root of the hierarchy of visitor objects.

For the Responsibility part: Three sentences about my main responsibility, what I'm doing, what services do I offer.

For the Collaborators Part: State my main collaborators and one line about how I interact with them.

Public API and Key Messages

  • label item

One simple example is simply gorgeous.

Internal Representation and Key Implementation Points.

Implementation Points

Instance Method Details

testBindQuestionMark

testBindQuestionMark

testBindQuestionMarkFromExistingStatement

testBindQuestionMarkFromExistingStatement
| result row statement |
conn supportsPreparedStatements 
ifFalse: ^self skip ].

statement := conn createStatement: 'CREATE TABLE CATS ( name varchar(50), owner varchar(50))'.
statement execute
statement := conn createStatement: 'INSERT INTO CATS(name,owner) VALUES('lutz','julien')'.
statement execute
statement := conn createStatement: 'SELECT * FROM CATS WHERE name=?'.
statement prepare
statement at: 1 bind: 'lutz'.
result := statement execute.
row := result first.
self assert: (row at: 1) equals: 'lutz'.
self assert: (row at: 2) equals: 'julien'

testBindQuestionMarkFromExistingUninitializedStatement

testBindQuestionMarkFromExistingUninitializedStatement
| result row statement |
conn supportsPreparedStatements 
ifFalse: ^self skip ].

statement := conn createStatement.
statement statementString: 'CREATE TABLE CATS ( name varchar(50), owner varchar(50))'.
statement execute
statement := conn createStatement.
statement statementString: 'INSERT INTO CATS(name,owner) VALUES('lutz','julien')'.
statement execute
statement := conn createStatement.
statement statementString: 'SELECT * FROM CATS WHERE name=' , (statement placeholderAt: 1).
statement prepare
statement at: 1 bind: 'lutz'.
result := statement execute.
row := result first.
self assert: (row at: 1) equals: 'lutz'.
self assert: (row at: 2) equals: 'julien'

testBindingFailsIfNotSupportedPrepare

testBindingFailsIfNotSupportedPrepare
| statement |
conn supportsPreparedStatements 
ifTrue: self skip ].

statement := conn createStatement.
statement statementString: 'SELECT * FROM CATS WHERE owner = ?'.
self should: statement at: 1 bind: 'guille' ] raise: Error

testPrepareInsert

testPrepareInsertFromExistingStatement

testPrepareInsertFromExistingStatement
| result row preparedStatement statement |
conn supportsPreparedStatements 
ifFalse: ^self skip ].

conn execute: 'INSERT INTO student(id) VALUES (1)'.
statement := conn createStatement: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', 1)'.
preparedStatement := statement prepare.
preparedStatement execute
result := conn execute: 'SELECT code, name, observations, id_student FROM signature'.
row := result first.
self assert: (row at: 1) equals: 59.
self assert: (row at: 2) equals: 'TADP'.
self assert: (row at: 3) equals: 'Tecnicas Av'.
self assert: (row at: 4) equals: 1

testPrepareInsertFromExistingUninitializedStatement

testPrepareInsertFromExistingUninitializedStatement
| result row preparedStatement statement |
conn supportsPreparedStatements 
ifFalse: ^self skip ].

conn execute: 'INSERT INTO student(id) VALUES (1)'.
statement := conn createStatement.
statement statementString: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', 1)'.
preparedStatement := statement prepare.
preparedStatement execute
result := conn execute: 'SELECT code, name, observations, id_student FROM signature'.
row := result first.
self assert: (row at: 1) equals: 59.
self assert: (row at: 2) equals: 'TADP'.
self assert: (row at: 3) equals: 'Tecnicas Av'.
self assert: (row at: 4) equals: 1

testPrepareSelect

testPrepareSelectFromExistingStatement

testPrepareSelectFromExistingUninitializedStatement

testPrepareSelectFromExistingUninitializedStatement

testPrepareWithArgs

testPrepareWithArgs
| result row preparedStatement |
conn supportsPreparedStatements 
ifFalse: ^self skip ].

conn execute: 'INSERT INTO student(id) VALUES (1)'.
preparedStatement := conn prepare: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', ?)'.
preparedStatement at: 1 bind: 1.
preparedStatement execute
preparedStatement := conn prepare: 'SELECT code, name, observations, id_student FROM signature WHERE id_student = ?'.
preparedStatement at: 1 bind: 1.
result := preparedStatement execute.
row := result first.
self assert: (row at: 1) equals: 59.
self assert: (row at: 2) equals: 'TADP'.
self assert: (row at: 3) equals: 'Tecnicas Av'.
self assert: (row at: 4) equals: 1

testPrepareWithArgsFromExistingStatement

testPrepareWithArgsFromExistingStatement
| result row preparedStatement |
conn supportsPreparedStatements 
ifFalse: ^self skip ].

conn execute: 'INSERT INTO student(id) VALUES (1)'.
preparedStatement := conn createStatement: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', ?)'.
preparedStatement prepare
preparedStatement at: 1 bind: 1.
preparedStatement execute
preparedStatement := conn createStatement: 'SELECT code, name, observations, id_student FROM signature WHERE id_student = ?'.
preparedStatement prepare
preparedStatement at: 1 bind: 1.
result := preparedStatement execute.
row := result first.
self assert: (row at: 1) equals: 59.
self assert: (row at: 2) equals: 'TADP'.
self assert: (row at: 3) equals: 'Tecnicas Av'.
self assert: (row at: 4) equals: 1

testPrepareWithArgsFromExistingUninitializedStatement

testPrepareWithArgsFromExistingUninitializedStatement
| result row preparedStatement |
conn supportsPreparedStatements 
ifFalse: ^self skip ].

conn execute: 'INSERT INTO student(id) VALUES (1)'.
preparedStatement := conn prepare: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', ?)'.
preparedStatement at: 1 bind: 1.
preparedStatement execute
preparedStatement := conn createStatement.
preparedStatement statementString: 'SELECT code, name, observations, id_student FROM signature WHERE id_student = ' , (preparedStatement placeholderAt: 1).
preparedStatement prepare
preparedStatement at: 1 bind: 1.
result := preparedStatement execute.
row := result first.
self assert: (row at: 1) equals: 59.
self assert: (row at: 2) equals: 'TADP'.
self assert: (row at: 3) equals: 'Tecnicas Av'.
self assert: (row at: 4) equals: 1

testPrepareWithUnboundArgsWithDriversThatChooseADefault

testPrepareWithUnboundArgsWithDriversThatChooseADefault
| preparedStatement |
conn supportsPreparedStatements 
ifFalse: ^self skip ].

conn notBoundArgumentsFail 
ifTrue: ^self skip ].

Not bound arguments are taken as NULL
preparedStatement := conn prepare: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', ?)'.
preparedStatement execute
(conn execute: 'SELECT id_student FROM signature') do: :r | self assert: (r at: 1) isNil ]

testPrepareWithUnboundArgsWithDriversThatChooseADefaultFromExistingStatement

testPrepareWithUnboundArgsWithDriversThatChooseADefaultFromExistingStatement
| preparedStatement |
conn supportsPreparedStatements 
ifFalse: ^self skip ].

conn notBoundArgumentsFail 
ifTrue: ^self skip ].

Not bound arguments are taken as NULL
preparedStatement := conn createStatement: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', ?)'.
preparedStatement prepare
preparedStatement execute
(conn execute: 'SELECT id_student FROM signature') do: :r | self assert: (r at: 1) isNil ]

testPrepareWithUnboundArgsWithDriversThatChooseADefaultFromExistingUninitializedStatement

testPrepareWithUnboundArgsWithDriversThatChooseADefaultFromExistingUninitializedStatement
| preparedStatement |
conn supportsPreparedStatements 
ifFalse: ^self skip ].

conn notBoundArgumentsFail 
ifTrue: ^self skip ].

Not bound arguments are taken as NULL
preparedStatement := conn createStatement.
preparedStatement statementString: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', ?)'.
preparedStatement prepare
preparedStatement execute
(conn execute: 'SELECT id_student FROM signature') do: :r | self assert: (r at: 1) isNil ]

testPrepareWithWrongArgs

testPrepareWithWrongArgs

testPrepareWithWrongArgsFromExistingStatement

testPrepareWithWrongArgsFromExistingStatement

testPrepareWithWrongArgsFromExistingUninitializedStatement

testPrepareWithWrongArgsFromExistingUninitializedStatement
| preparedStatement |
conn supportsPreparedStatements 
ifFalse: ^self skip ].

conn notBoundArgumentsFail 
ifFalse: self skip ].

preparedStatement := conn createStatement.
preparedStatement statementString: ('INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', ' , (preparedStatement placeholderAt: 1)) , ')'.
preparedStatement prepare
self should: preparedStatement execute ] raise: Error

testStatementNotPreparedIfNotSuported

If we send non-sense, drivers that support prepared statements will fail on preparation and the others will fail on execute as there is no real preparation

testStatementNotPreparedIfNotSuported

testStatementNotPreparedIfNotSuportedFromExistingStatement

If we send non-sense, drivers that support prepared statements will fail on preparation and the others will fail on execute as there is no real preparation

testStatementNotPreparedIfNotSuportedFromExistingStatement
| preparedStatement |
conn supportsPreparedStatements 
ifTrue: ^self skip ].

preparedStatement := conn createStatement: 'SELECT 1+1'.
self should: preparedStatement prepare ] raise: Error

testStatementNotPreparedIfNotSuportedFromExistingUninitializedStatement

If we send non-sense, drivers that support prepared statements will fail on preparation and the others will fail on execute as there is no real preparation

testStatementNotPreparedIfNotSuportedFromExistingUninitializedStatement
| statement |
conn supportsPreparedStatements 
ifTrue: ^self skip ].

statement := conn createStatement.
statement statementString: 'SELECT 1+1'.
self should: conn prepare ] raise: Error