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| result row statement |
conn supportsPreparedStatements
conn execute: 'CREATE TABLE CATS (
name varchar(50),
owner varchar(50))'.
conn execute: 'INSERT INTO CATS(name,owner) VALUES('lutz','julien')'.
statement := conn prepare: 'SELECT * FROM CATS WHERE name=?'.
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'
testBindQuestionMarkFromExistingStatement
testBindQuestionMarkFromExistingStatement| result row statement |
conn supportsPreparedStatements
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
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
statement := conn createStatement.
statement statementString: 'SELECT * FROM CATS WHERE owner = ?'.
self should: [ statement at: 1 bind: 'guille' ] raise: Error
testPrepareInsert
testPrepareInsert| result row preparedStatement |
conn supportsPreparedStatements
conn execute: 'INSERT INTO student(id) VALUES (1)'.
preparedStatement := conn prepare: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', 1)'.
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
testPrepareInsertFromExistingStatement
testPrepareInsertFromExistingStatement| result row preparedStatement statement |
conn supportsPreparedStatements
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
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
testPrepareSelect| result row preparedStatement |
conn supportsPreparedStatements
conn execute: 'INSERT INTO student(id) VALUES (1)'.
conn execute: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', 1)'.
preparedStatement := conn prepare: 'SELECT code, name, observations, id_student FROM signature'.
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
testPrepareSelectFromExistingStatement
testPrepareSelectFromExistingStatement| result row statement |
conn supportsPreparedStatements
conn execute: 'INSERT INTO student(id) VALUES (1)'.
conn execute: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', 1)'.
statement := conn createStatement: 'SELECT code, name, observations, id_student FROM signature'.
result := statement prepare 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
testPrepareSelectFromExistingUninitializedStatement
testPrepareSelectFromExistingUninitializedStatement| result row preparedStatement |
conn supportsPreparedStatements
conn execute: 'INSERT INTO student(id) VALUES (1)'.
conn execute: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', 1)'.
preparedStatement := conn createStatement.
preparedStatement statementString: 'SELECT code, name, observations, id_student FROM signature'.
preparedStatement prepare
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
testPrepareWithArgs
testPrepareWithArgs| result row preparedStatement |
conn supportsPreparedStatements
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
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
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
conn notBoundArgumentsFail
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
conn notBoundArgumentsFail
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
conn notBoundArgumentsFail
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| preparedStatement |
conn supportsPreparedStatements
conn notBoundArgumentsFail
preparedStatement := conn prepare: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', ?)'.
self should: [ preparedStatement execute ] raise: Error
testPrepareWithWrongArgsFromExistingStatement
testPrepareWithWrongArgsFromExistingStatement| preparedStatement |
conn supportsPreparedStatements
conn notBoundArgumentsFail
preparedStatement := conn createStatement: 'INSERT INTO signature(code, name, observations, id_student) VALUES (59, 'TADP', 'Tecnicas Av', ?)'.
preparedStatement prepare
self should: [ preparedStatement execute ] raise: Error
testPrepareWithWrongArgsFromExistingUninitializedStatement
testPrepareWithWrongArgsFromExistingUninitializedStatement| preparedStatement |
conn supportsPreparedStatements
conn notBoundArgumentsFail
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
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
statement := conn createStatement.
statement statementString: 'SELECT 1+1'.
self should: [ conn prepare ] raise: Error