From cdbc85465f26bedf282ebb63f4e59665801f451b Mon Sep 17 00:00:00 2001 From: Torsten Bergmann Date: Sun, 17 Sep 2023 21:46:00 +0200 Subject: [PATCH 1/5] Fix and review SQLite3-Inspector-Extensions --- .../AbstractFileReference.extension.st | 20 +++++++++---------- .../SQLite3Database.extension.st | 4 ++-- .../SQLite3Row.extension.st | 12 +++++------ .../SQLite3Table.extension.st | 18 ++++++++--------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/SQLite3-Inspector-Extensions/AbstractFileReference.extension.st b/src/SQLite3-Inspector-Extensions/AbstractFileReference.extension.st index 13f6d51..5999b65 100644 --- a/src/SQLite3-Inspector-Extensions/AbstractFileReference.extension.st +++ b/src/SQLite3-Inspector-Extensions/AbstractFileReference.extension.st @@ -5,20 +5,20 @@ AbstractFileReference >> databaseSize [ |s| s := self size. s / 1024 > 1024 ifTrue: [ ^ ((s / 1024 / 1024) roundDownTo: 0.01) asString, ' MB' ]. - ^ ((s / 1024) roundDownTo: 0.01) asString, ' KB' + ^ ((s / 1024) roundDownTo: 0.01) asString, ' KB' ] { #category : #'*SQLite3-Inspector-Extensions' } AbstractFileReference >> inspectionSQLite3Info [ - + | label1 label2 | label1 := SpLabeledPresenter label: 'Database file:' input: (SpTextInputFieldPresenter new text: self fullName). label2 := SpLabeledPresenter label: 'Database size:' - input: (SpTextInputFieldPresenter new text: self databaseSize). + input: (SpTextInputFieldPresenter new text: self databaseSize). ^ SpPresenter new layout: (SpBoxLayout newTopToBottom add: label1; @@ -29,14 +29,14 @@ AbstractFileReference >> inspectionSQLite3Info [ { #category : #'*SQLite3-Inspector-Extensions' } AbstractFileReference >> inspectionSQLite3InfoContext: aContext [ - + ^ aContext active: self isSQlite3Database ] { #category : #'*SQLite3-Inspector-Extensions' } AbstractFileReference >> inspectionSQLite3Tables [ - + ^ SpTablePresenter new items: (SQLite3Database tableInfoFor: self fullName); addColumn: (SpStringTableColumn title: 'Table Name' evaluated: [ :assoc | assoc name ]); @@ -46,16 +46,16 @@ AbstractFileReference >> inspectionSQLite3Tables [ { #category : #'*SQLite3-Inspector-Extensions' } AbstractFileReference >> inspectionSQLite3TablesContext: aContext [ - + ^ aContext active: self isSQlite3Database ] { #category : #'*SQLite3-Inspector-Extensions' } AbstractFileReference >> isSQlite3Database [ - "Return true if the reference is an SQlite3 database file" - - ^ self isFile and: [ - self extension = 'db' and: [ + "Return true if the reference is an SQLite3 database file" + + ^ self isFile and: [ + self extension = 'db' and: [ (self readStreamDo: [ :s | s next: 16 ]) = ('SQLite format 3' , Character null asString) ] ] ] diff --git a/src/SQLite3-Inspector-Extensions/SQLite3Database.extension.st b/src/SQLite3-Inspector-Extensions/SQLite3Database.extension.st index 45db4c3..f332863 100644 --- a/src/SQLite3-Inspector-Extensions/SQLite3Database.extension.st +++ b/src/SQLite3-Inspector-Extensions/SQLite3Database.extension.st @@ -3,10 +3,10 @@ Extension { #name : #SQLite3Database } { #category : #'*SQLite3-Inspector-Extensions' } SQLite3Database >> inspectionSQLite3Tables [ - + ^ SpTablePresenter new items: self tables; addColumn: (SpStringTableColumn title: 'Name' evaluated: [ :assoc | assoc name ]); - addColumn: (SpStringTableColumn title: 'Number of rows' evaluated: [ :assoc | assoc numberOfRows ]); + addColumn: (SpStringTableColumn title: 'Number of rows' evaluated: [ :assoc | assoc numberOfRows ]); yourself ] diff --git a/src/SQLite3-Inspector-Extensions/SQLite3Row.extension.st b/src/SQLite3-Inspector-Extensions/SQLite3Row.extension.st index 98df94c..6cf3e04 100644 --- a/src/SQLite3-Inspector-Extensions/SQLite3Row.extension.st +++ b/src/SQLite3-Inspector-Extensions/SQLite3Row.extension.st @@ -3,14 +3,14 @@ Extension { #name : #SQLite3Row } { #category : #'*SQLite3-Inspector-Extensions' } SQLite3Row >> inspectionSQLite3Row [ - + | presenter | presenter := SpTablePresenter new. presenter items: (Array with: self). - self columnNames do: [:each | + self columnNames do: [:each | presenter addColumn: (SpStringTableColumn title: each evaluated: [ :assoc | self at: each ]) - - ]. - - ^presenter + + ]. + + ^presenter ] diff --git a/src/SQLite3-Inspector-Extensions/SQLite3Table.extension.st b/src/SQLite3-Inspector-Extensions/SQLite3Table.extension.st index e4383eb..8dd058d 100644 --- a/src/SQLite3-Inspector-Extensions/SQLite3Table.extension.st +++ b/src/SQLite3-Inspector-Extensions/SQLite3Table.extension.st @@ -3,25 +3,25 @@ Extension { #name : #SQLite3Table } { #category : #'*SQLite3-Inspector-Extensions' } SQLite3Table >> inspectionSQLite3Columns [ - + ^ SpTablePresenter new items: self columns; - addColumn: (SpStringTableColumn title: 'Column Name' evaluated: [ :each | each name ]); + addColumn: (SpStringTableColumn title: 'Column Name' evaluated: [ :each | each name ]); addColumn: (SpStringTableColumn title: 'Column Type' evaluated: [ :each | each type ]); - addColumn: (SpStringTableColumn title: 'Non-empty values' evaluated: [ :each | each hasNotNullConstraint ifTrue: 'NOT NULL' ifFalse: '' ]); + addColumn: (SpStringTableColumn title: 'Non-empty values' evaluated: [ :each | each hasNotNullConstraint ifTrue: 'NOT NULL' ifFalse: '' ]); yourself ] { #category : #'*SQLite3-Inspector-Extensions' } SQLite3Table >> inspectionSQLite3Data [ - + | presenter | presenter := SpTablePresenter new. presenter items: self rows. - + self columnNames do: [:col | - presenter addColumn: (SpStringTableColumn title: col evaluated: [ :each | each at: col ]) + presenter addColumn: (SpStringTableColumn title: col evaluated: [ :each | each at: col ]) ]. ^presenter ] @@ -29,7 +29,7 @@ SQLite3Table >> inspectionSQLite3Data [ { #category : #'*SQLite3-Inspector-Extensions' } SQLite3Table >> inspectionSQLite3Schema [ - + ^ SpTextPresenter new text: self schema; yourself @@ -38,10 +38,10 @@ SQLite3Table >> inspectionSQLite3Schema [ { #category : #'*SQLite3-Inspector-Extensions' } SQLite3Table >> inspectionSQLite3TableProperties [ - + ^ SpTablePresenter new items: self properties associations; addColumn: (SpStringTableColumn title: 'Property' evaluated: [ :assoc | assoc key ]); - addColumn: (SpStringTableColumn title: 'Value' evaluated: [ :assoc | assoc value ]); + addColumn: (SpStringTableColumn title: 'Value' evaluated: [ :assoc | assoc value ]); yourself ] From eda1fe12a06ff9509299f2d564d89b11e604e556 Mon Sep 17 00:00:00 2001 From: Torsten Bergmann Date: Sun, 17 Sep 2023 21:53:21 +0200 Subject: [PATCH 2/5] Fix and review SQLite3-Core-Tests --- .../SQLite3BaseConnectionTest.class.st | 170 +++++++++--------- .../SQLite3ColumnTest.class.st | 19 +- .../SQLite3ConnectionTest.class.st | 164 ++++++++--------- .../SQLite3RowTest.class.st | 39 ++-- .../SQLite3TableTest.class.st | 11 +- 5 files changed, 187 insertions(+), 216 deletions(-) diff --git a/src/SQLite3-Core-Tests/SQLite3BaseConnectionTest.class.st b/src/SQLite3-Core-Tests/SQLite3BaseConnectionTest.class.st index 99f14ab..9a426f5 100644 --- a/src/SQLite3-Core-Tests/SQLite3BaseConnectionTest.class.st +++ b/src/SQLite3-Core-Tests/SQLite3BaseConnectionTest.class.st @@ -14,33 +14,33 @@ Class { { #category : #'tests - DEACTIVATED' } SQLite3BaseConnectionTest >> deactivatedTestTracing [ | sql callback expected actual | - + (SystemVersion current major >= 7) ifTrue: [ self skip ]. "This test invokes a callback from SQLite to Pharo. It works in Pharo 6 and earlier but not in Pharo 7." - + sql := #('create table if not exists x (xk integer primary key, iv integer, tv text)' 'insert into x values (NULL, 1, ''two'')' 'drop table x'). - + expected := String streamContents: [ :s | s nextPutAll: sql first; cr; nextPutAll: sql second; cr; nextPutAll: sql third; cr ]. - + actual := WriteStream on: String new. - - callback := FFICallback + + callback := FFICallback signature: #(void (ExternalAddress appData, String sqlText)) block: [ :appdata :sqltext | "We ignore appdata in this test, because we're passing a null pointer in." actual nextPutAll: sqltext; cr ]. - + "The null pointer appears as appdata in the callback." - db traceUsing: callback with: ExternalAddress new. - + db traceUsing: callback with: ExternalAddress new. + res := db basicExecute: sql first. self assert: res equals: 0. - + res := db basicExecute: sql second. self assert: res equals: 0. @@ -116,20 +116,18 @@ SQLite3BaseConnectionTest >> noTestColumnNamesBobbyGo [ ] { #category : #running } -SQLite3BaseConnectionTest >> setUp [ +SQLite3BaseConnectionTest >> setUp [ super setUp. db := SQLite3BaseConnection on: ':memory:'. - db open. - + db open ] { #category : #running } SQLite3BaseConnectionTest >> tearDown [ - + [ db close ] on: SQLite3Misuse do: [ ]. super tearDown - ] { #category : #'tests - connections' } @@ -146,8 +144,7 @@ SQLite3BaseConnectionTest >> testBadOpen [ SQLite3BaseConnectionTest >> testBasicExecuteOk [ self executeInDB: 'create table x (xk integer, xv integer);'. - self executeInDB: 'drop table x;'. - + self executeInDB: 'drop table x;' ] { #category : #'tests - execution' } @@ -155,7 +152,6 @@ SQLite3BaseConnectionTest >> testBasicExecuteSyntaxError [ self should: [ db basicExecute: 'create table,;' ] raise: SQLite3AbstractError - ] { #category : #'tests - types' } @@ -163,7 +159,7 @@ SQLite3BaseConnectionTest >> testBooleanColumnTypeMismatch [ self executeInDB: 'create table x (xk integer primary key, xv notboolean);'. - self withPreparedStatement: 'select xv from x' do: [ :statement | + self withPreparedStatement: 'select xv from x' do: [ :statement | statement basicExecute: [ :row | self should: [ row booleanAt: 0 ] raise: SQLite3AbstractError ] ] ] @@ -173,15 +169,15 @@ SQLite3BaseConnectionTest >> testBooleanObject [ self executeInDB: 'create table x (xk integer primary key, xv boolean);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | statement at: 1 putObject: true. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x' do: [ :statement | + statement basicExecute: [ :row | | value | value := row objectAt: 0. @@ -195,14 +191,14 @@ SQLite3BaseConnectionTest >> testBooleanWriteIntegerOneThenRead [ self executeInDB: 'create table x (xk integer primary key, xv boolean);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | statement at: 1 putInteger: 1. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x' do: [ :statement | + statement basicExecute: [ :row | | value | value := row booleanAt: 0. @@ -216,13 +212,13 @@ SQLite3BaseConnectionTest >> testBooleanWriteIntegerTwoThenRead [ self executeInDB: 'create table x (xk integer primary key, xv boolean);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | statement at: 1 putInteger: 2. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | + self withPreparedStatement: 'select xv from x' do: [ :statement | statement basicExecute: [ :row | self should: [ row booleanAt: 0 ] raise: SQLite3AbstractError ] ] ] @@ -231,14 +227,14 @@ SQLite3BaseConnectionTest >> testBooleanWriteIntegerZeroThenRead [ self executeInDB: 'create table x (xk integer primary key, xv boolean);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | statement at: 1 putInteger: 0. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x' do: [ :statement | + statement basicExecute: [ :row | | value | value := row booleanAt: 0. @@ -252,15 +248,15 @@ SQLite3BaseConnectionTest >> testBooleanWriteNilThenRead [ self executeInDB: 'create table x (xk integer primary key, xv boolean);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | statement at: 1 putNil: nil. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x' do: [ :statement | + statement basicExecute: [ :row | | value | value := row booleanAt: 0. @@ -277,8 +273,8 @@ SQLite3BaseConnectionTest >> testBooleanWriteSQLNullThenRead [ self withPreparedStatement: 'insert into x values (NULL, NULL)' do: [ :statement | statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x' do: [ :statement | + statement basicExecute: [ :row | | value | value := row booleanAt: 0. @@ -292,14 +288,14 @@ SQLite3BaseConnectionTest >> testBooleanWriteStringFalseThenRead [ self executeInDB: 'create table x (xk integer primary key, xv boolean);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | statement at: 1 putString: 'false'. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x' do: [ :statement | + statement basicExecute: [ :row | | value | value := row booleanAt: 0. @@ -313,14 +309,14 @@ SQLite3BaseConnectionTest >> testBooleanWriteStringTrueThenRead [ self executeInDB: 'create table x (xk integer primary key, xv boolean);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | statement at: 1 putString: 'true'. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x' do: [ :statement | + statement basicExecute: [ :row | | value | value := row booleanAt: 0. @@ -334,13 +330,13 @@ SQLite3BaseConnectionTest >> testBooleanWriteStringTwoThenRead [ self executeInDB: 'create table x (xk integer primary key, xv boolean);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | statement at: 1 putString: '2'. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | + self withPreparedStatement: 'select xv from x' do: [ :statement | statement basicExecute: [ :row | self should: [ row booleanAt: 0 ] raise: SQLite3AbstractError ] ] ] @@ -349,14 +345,14 @@ SQLite3BaseConnectionTest >> testBooleanWriteThenRead [ self executeInDB: 'create table x (xk integer primary key, xv boolean);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | statement at: 1 putBoolean: true. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x' do: [ :statement | + statement basicExecute: [ :row | | value | value := row booleanAt: 0. @@ -444,7 +440,7 @@ SQLite3BaseConnectionTest >> testDataValuesAvailable [ self withPreparedStatement: 'select * from x' - do: [ :statement | + do: [ :statement | statement basicExecute: [ :row | self assert: row dataValuesAvailable equals: 3 ] ] ] @@ -458,15 +454,15 @@ SQLite3BaseConnectionTest >> testDate [ self executeInDB: 'create table x (xv date);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (?)' do: [ :statement | statement at: 1 putDateTime: data. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x' do: [ :statement | + statement basicExecute: [ :row | | value | value := row dateTimeAt: 0. @@ -488,15 +484,15 @@ SQLite3BaseConnectionTest >> testDateAndTime [ self executeInDB: 'create table x (xv datetime);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (?)' do: [ :statement | statement at: 1 putDateTime: data. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x' do: [ :statement | + statement basicExecute: [ :row | | value | value := row dateTimeAt: 0. @@ -533,8 +529,8 @@ SQLite3BaseConnectionTest >> testDefaultMultilingualStrings [ self withPreparedStatement: 'insert into x (xk) values (NULL)' do: [ :statement | statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xm1, xm2 from x order by xk' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xm1, xm2 from x order by xk' do: [ :statement | + statement basicExecute: [ :row | self assert: ( row stringAt: 0 ) equals: '中文'. self assert: ( row stringAt: 1 ) equals: 'áěšřčá' ] @@ -543,7 +539,7 @@ SQLite3BaseConnectionTest >> testDefaultMultilingualStrings [ { #category : #'tests - connections' } SQLite3BaseConnectionTest >> testDoubleClose [ - + db close. [ db close ] on: SQLite3Misuse do: [ ] "#tearDown will close the db again, and is similarly guarded." @@ -555,8 +551,8 @@ SQLite3BaseConnectionTest >> testFloat [ self executeInDB: 'create table x (xk integer primary key, xv real);'. self executeInDB: 'insert into x values (NULL, 1.141);'. - self withPreparedStatement: 'select * from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select * from x' do: [ :statement | + statement basicExecute: [ :row | self assert: ( row nameOfColumn: 1 ) equals: 'xv'. self assert: ( row floatAt: 1 ) equals: 1.141 ] @@ -570,13 +566,13 @@ SQLite3BaseConnectionTest >> testInteger [ self executeInDB: 'create table x (xk integer primary key, xv integer);'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | statement at: 1 putInteger: 3212321555. statement step ]. - self withPreparedStatement: 'select * from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select * from x' do: [ :statement | + statement basicExecute: [ :row | self assert: ( row nameOfColumn: 1 ) equals: 'xv'. self assert: ( row integerAt: 1 ) equals: 3212321555 ] @@ -584,9 +580,9 @@ SQLite3BaseConnectionTest >> testInteger [ ] { #category : #tests } -SQLite3BaseConnectionTest >> testIsAbstract [ +SQLite3BaseConnectionTest >> testIsAbstract [ - self assert: SQLite3BaseConnection isAbstract + self assert: SQLite3BaseConnection isAbstract ] { #category : #tests } @@ -603,8 +599,8 @@ SQLite3BaseConnectionTest >> testMultilingualStrings [ data := OrderedCollection with: 'English' with: '中文' with: 'にほんご' , 'áěšřčá'. self executeInDB: 'create table x (xk integer primary key, xv varchar);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | - data do: [ :ea | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + data do: [ :ea | statement at: 1 putString: ea. statement step; @@ -615,8 +611,8 @@ SQLite3BaseConnectionTest >> testMultilingualStrings [ self executeInDB: 'commit'. index := 1. - self withPreparedStatement: 'select xv from x order by xk asc' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x order by xk asc' do: [ :statement | + statement basicExecute: [ :row | self assert: ( row stringAt: 0 ) equals: ( data at: index ). index := index + 1 ] @@ -633,7 +629,7 @@ SQLite3BaseConnectionTest >> testMultilingualTableName [ self withPreparedStatement: 'select xm1 from 表一 order by xk' - do: [ :statement | + do: [ :statement | statement basicExecute: [ :row | self assert: ( row stringAt: 0 ) equals: '中文' ] ] ] @@ -648,15 +644,15 @@ SQLite3BaseConnectionTest >> testObjectBlob [ executeInDB: 'create table x (xk integer primary key, xv blob);'; executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | statement at: 1 putObject: data. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x' do: [ :statement | + statement basicExecute: [ :row | | value | value := row objectAt: 0. @@ -674,9 +670,9 @@ SQLite3BaseConnectionTest >> testPrepareStep [ self executeInDB: 'create table x (xk integer primary key, iv integer, tv text);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?, ?)' do: [ :statement | self assert: statement sqlText equals: 'insert into x values (NULL, ?, ?)'. - 1 to: 10 do: [ :x | + 1 to: 10 do: [ :x | statement at: 1 putInteger: x * x. statement at: 2 putString: ( '<1p> * <1p>' expandMacrosWith: x ). statement step. @@ -686,11 +682,11 @@ SQLite3BaseConnectionTest >> testPrepareStep [ ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select * from x' do: [ :statement | + self withPreparedStatement: 'select * from x' do: [ :statement | | i | self assert: statement sqlText equals: 'select * from x'. - statement basicExecute: [ :row | + statement basicExecute: [ :row | i := row integerAt: 0. self assert: ( row integerAt: 1 ) equals: i * i. self assert: ( row stringAt: 2 ) equals: ( '<1p> * <1p>' expandMacrosWith: i ) @@ -705,9 +701,9 @@ SQLite3BaseConnectionTest >> testPrepareStepSelective [ self executeInDB: 'create table x (xk integer primary key, iv integer, tv text);'. self executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (NULL, ?, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?, ?)' do: [ :statement | self assert: statement sqlText equals: 'insert into x values (NULL, ?, ?)'. - 1 to: 10 do: [ :x | + 1 to: 10 do: [ :x | statement at: 1 putInteger: x * x; at: 2 putString: x asString , ' * ' , x asString; @@ -719,10 +715,10 @@ SQLite3BaseConnectionTest >> testPrepareStepSelective [ self executeInDB: 'commit'. count := 0. - self withPreparedStatement: 'select * from x where iv < ?' do: [ :statement | + self withPreparedStatement: 'select * from x where iv < ?' do: [ :statement | self assert: statement sqlText equals: 'select * from x where iv < ?'. statement at: 1 putInteger: 27. - statement basicExecute: [ :row | + statement basicExecute: [ :row | count := count + 1. i := row integerAt: 0. self assert: ( row integerAt: 1 ) equals: i * i. @@ -738,8 +734,8 @@ SQLite3BaseConnectionTest >> testResultSetColumnIntrospection [ self executeInDB: 'create table x (xk integer primary key, iv integer, tv text);'. self executeInDB: 'insert into x values (NULL, 1, "duh");'. - self withPreparedStatement: 'select * from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select * from x' do: [ :statement | + statement basicExecute: [ :row | self assert: ( row nameOfColumn: 0 ) equals: 'xk'. self assert: ( row valueOfColumn: 0 ) equals: 1. self assert: ( row nameOfColumn: 1 ) equals: 'iv'. @@ -762,13 +758,13 @@ SQLite3BaseConnectionTest >> testScaledDecimal [ self executeInDB: 'create table x (xk integer primary key, xv real);'. - self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (NULL, ?)' do: [ :statement | statement at: 1 putFloat: number. statement step ]. - self withPreparedStatement: 'select * from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select * from x' do: [ :statement | + statement basicExecute: [ :row | self assert: ( row nameOfColumn: 1 ) equals: 'xv'; assert: ( row floatAt: 1 ) equals: float @@ -807,14 +803,14 @@ SQLite3BaseConnectionTest >> testTime [ executeInDB: 'create table x (xv time);'; executeInDB: 'begin'. - self withPreparedStatement: 'insert into x values (?)' do: [ :statement | + self withPreparedStatement: 'insert into x values (?)' do: [ :statement | statement at: 1 putTime: data. statement step ]. self executeInDB: 'commit'. - self withPreparedStatement: 'select xv from x' do: [ :statement | - statement basicExecute: [ :row | + self withPreparedStatement: 'select xv from x' do: [ :statement | + statement basicExecute: [ :row | | value | value := row timeAt: 0. diff --git a/src/SQLite3-Core-Tests/SQLite3ColumnTest.class.st b/src/SQLite3-Core-Tests/SQLite3ColumnTest.class.st index 3005cdb..75ffaef 100644 --- a/src/SQLite3-Core-Tests/SQLite3ColumnTest.class.st +++ b/src/SQLite3-Core-Tests/SQLite3ColumnTest.class.st @@ -32,17 +32,18 @@ SQLite3ColumnTest >> tableCreationScript [ ] { #category : #running } -SQLite3ColumnTest >> tearDown [ +SQLite3ColumnTest >> tearDown [ + db connection close. db := nil. - super tearDown + super tearDown ] { #category : #tests } SQLite3ColumnTest >> testHasNotNullConstraint [ - + self assert: firstColumn hasNotNullConstraint. - self deny: secondColumn hasNotNullConstraint + self deny: secondColumn hasNotNullConstraint ] { #category : #tests } @@ -57,7 +58,7 @@ SQLite3ColumnTest >> testInitialization [ | instance | instance := SQLite3Column new. - self deny: instance hasNotNullConstraint + self deny: instance hasNotNullConstraint ] { #category : #tests } @@ -69,14 +70,14 @@ SQLite3ColumnTest >> testName [ { #category : #tests } SQLite3ColumnTest >> testPrintString [ - + self assert: firstColumn printString equals: 'a SQLite3Column("ID")'. - self assert: secondColumn printString equals: 'a SQLite3Column("NAME")' + self assert: secondColumn printString equals: 'a SQLite3Column("NAME")' ] { #category : #tests } SQLite3ColumnTest >> testType [ - + self assert: firstColumn type equals: 'INTEGER'. - self assert: secondColumn type equals: 'NVARCHAR(120)' + self assert: secondColumn type equals: 'NVARCHAR(120)' ] diff --git a/src/SQLite3-Core-Tests/SQLite3ConnectionTest.class.st b/src/SQLite3-Core-Tests/SQLite3ConnectionTest.class.st index 398eed3..1bc5925 100644 --- a/src/SQLite3-Core-Tests/SQLite3ConnectionTest.class.st +++ b/src/SQLite3-Core-Tests/SQLite3ConnectionTest.class.st @@ -25,38 +25,34 @@ SQLite3ConnectionTest >> executeInDB: anSQLText [ { #category : #utilities } SQLite3ConnectionTest >> populateRowsInto: tableName of: database [ | rand rows schema insert rn rt | - rand := Random new. + rand := Random new. rows := rand nextInt: 100. schema := 'create table ', tableName, ' (rk integer primary key, rn integer, rt text);'. insert := 'insert into ', tableName, ' values (?, ?, ?)'. - - database basicExecute: 'begin'. - database basicExecute: schema. + + database basicExecute: 'begin'. + database basicExecute: schema. 1 to: rows do: [ :i | rn := i * (rand nextInt: 10). rt := i asString, '-ZZZ'. - database execute: insert with: (Array with: i with: rn with: rt) ]. + database execute: insert with: (Array with: i with: rn with: rt) ]. database basicExecute: 'commit'. - - ^ rows - - + ^ rows ] { #category : #running } -SQLite3ConnectionTest >> setUp [ +SQLite3ConnectionTest >> setUp [ super setUp. db := SQLite3Connection memory. - db open. - + db open ] { #category : #running } SQLite3ConnectionTest >> tearDown [ - + [ db close ] on: SQLite3Misuse do: [ ]. [ target ifNotNil:[target close] ] on: SQLite3Misuse do: [ ]. super tearDown @@ -65,20 +61,18 @@ SQLite3ConnectionTest >> tearDown [ { #category : #tests } SQLite3ConnectionTest >> testBackup [ | row backup | - + target := SQLite3Connection memory. target open. self populateRowsInto: 'junk' of: db. backup := db backupTo: target. backup open; step; finish. row := (target execute: 'select * from junk where rt = ''1-ZZZ''') onlyRow. - + self assert: (row at: 'rk') equals: 1. self assert: (row at: 'rt') equals: '1-ZZZ'. self assert: (row at: 1) equals: 1. - self assert: (row at: 3) equals: '1-ZZZ'. - - + self assert: (row at: 3) equals: '1-ZZZ' ] { #category : #tests } @@ -87,34 +81,29 @@ SQLite3ConnectionTest >> testChanges [ count := self populateRowsInto: 'stuff' of: db. self assert: db changes equals: 1. (db basicExecute: 'delete from stuff'). - self assert: db changes equals: count. - + self assert: db changes equals: count ] { #category : #tests } SQLite3ConnectionTest >> testExactlyOneRow [ | row | - + self populateRowsInto: 'junk' of: db. row := (db execute: 'select * from junk where rt = ''1-ZZZ''') onlyRow. - + self assert: (row at: 'rk') equals: 1. self assert: (row at: 'rt') equals: '1-ZZZ'. self assert: (row at: 1) equals: 1. - self assert: (row at: 3) equals: '1-ZZZ'. - - + self assert: (row at: 3) equals: '1-ZZZ' ] { #category : #tests } SQLite3ConnectionTest >> testExactlyOneRowGotNone [ | row | - + self populateRowsInto: 'junk' of: db. row := (db execute: 'select * from junk where rt = ''0-ZZZ''') onlyRow. - self assert: row isNil. - - + self assert: row isNil ] { #category : #tests } @@ -138,20 +127,18 @@ SQLite3ConnectionTest >> testExecuteDrop [ { #category : #tests } SQLite3ConnectionTest >> testExecuteNoResult [ - + rs := db execute: 'create table if not exists x (xk integer primary key, iv integer, tv text);'. self assert: (rs next isNil). rs close. - + rs := db execute: 'delete from x;'. self assert: (rs next isNil). rs close. - + rs := db execute: 'drop table x;'. self assert: (rs next isNil). - rs close. - - + rs close ] { #category : #tests } @@ -573,7 +560,7 @@ SQLite3ConnectionTest >> testExecuteWithInsertMultilingualStringsThenSelect [ self executeInDB: 'delete from x;'. self executeInDB: 'begin'. s := db prepare: 'insert into x values (NULL, ?)'. - data do: [ :x | + data do: [ :x | s at: 1 putString: x. s step. s clearBindings. @@ -584,7 +571,7 @@ SQLite3ConnectionTest >> testExecuteWithInsertMultilingualStringsThenSelect [ idx := 1. rs := db execute: 'select xk, tv from x order by xk asc'. - [ ( row := rs next ) isNotNil ] whileTrue: [ + [ ( row := rs next ) isNotNil ] whileTrue: [ self assert: ( row at: 'xk' ) equals: idx. self assert: ( row at: 'tv' ) equals: ( data at: idx ). idx := idx + 1 @@ -706,7 +693,7 @@ SQLite3ConnectionTest >> testExecuteWithInsertThenSelect3 [ self executeInDB: 'delete from x;'. self executeInDB: 'begin'. s := db prepare: 'insert into x values (NULL, ?, ?)'. - 1 to: 10 do: [ :x | + 1 to: 10 do: [ :x | s at: 1 putInteger: x * x. s at: 2 putString: x asString , ' * ' , x asString. s step. @@ -718,7 +705,7 @@ SQLite3ConnectionTest >> testExecuteWithInsertThenSelect3 [ idx := 1. rs := db execute: 'select * from x where iv < ?' with: #( 27 ). - [ ( row := rs next ) isNotNil ] whileTrue: [ + [ ( row := rs next ) isNotNil ] whileTrue: [ self assert: ( row at: 'xk' ) equals: idx. self assert: ( row at: 'iv' ) equals: idx * idx. self assert: ( row at: 'tv' ) equals: idx asString , ' * ' , idx asString. @@ -743,7 +730,7 @@ SQLite3ConnectionTest >> testExecuteWithInsertThenSelectChineseTableName [ self executeInDB: 'delete from 表一;'. self executeInDB: 'begin'. s := db prepare: 'insert into 表一 values (NULL, ?)'. - data do: [ :x | + data do: [ :x | s at: 1 putString: x. s step. s clearBindings. @@ -754,7 +741,7 @@ SQLite3ConnectionTest >> testExecuteWithInsertThenSelectChineseTableName [ idx := 1. rs := db execute: 'select xk, tv from 表一 order by xk asc'. - [ ( row := rs next ) isNotNil ] whileTrue: [ + [ ( row := rs next ) isNotNil ] whileTrue: [ self assert: ( row at: 'xk' ) equals: idx. self assert: ( row at: 'tv' ) equals: ( data at: idx ). idx := idx + 1 @@ -807,7 +794,7 @@ SQLite3ConnectionTest >> testExecuteWithInsertThenSelectJapaneseTableName [ self executeInDB: 'delete from テーブル一;'. self executeInDB: 'begin'. s := db prepare: 'insert into テーブル一 values (NULL, ?)'. - data do: [ :x | + data do: [ :x | s at: 1 putString: x. s step. s clearBindings. @@ -818,7 +805,7 @@ SQLite3ConnectionTest >> testExecuteWithInsertThenSelectJapaneseTableName [ idx := 1. rs := db execute: 'select xk, tv from テーブル一 order by xk asc'. - [ ( row := rs next ) isNotNil ] whileTrue: [ + [ ( row := rs next ) isNotNil ] whileTrue: [ self assert: ( row at: 'xk' ) equals: idx. self assert: ( row at: 'tv' ) equals: ( data at: idx ). idx := idx + 1 @@ -863,104 +850,97 @@ SQLite3ConnectionTest >> testExecuteWithToFail2 [ { #category : #tests } SQLite3ConnectionTest >> testGetAutocommit [ - + self assert: db getAutoCommit equals: true. db beginTransaction. self assert: db getAutoCommit equals: false. db rollbackTransaction. - self assert: db getAutoCommit equals: true. - - + self assert: db getAutoCommit equals: true ] { #category : #'tests - glorp compatibility' } SQLite3ConnectionTest >> testGlorpAutoID [ | schema rows | - + schema := 'CREATE TABLE BOOK (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, STUFF TEXT NOT NULL);'. - + db basicExecute: schema. db beginTransaction. - db execute: 'insert into BOOK (STUFF) values (?)' + db execute: 'insert into BOOK (STUFF) values (?)' with: #('The Bad Beginning'). - db execute: 'insert into BOOK (STUFF) values (?)' + db execute: 'insert into BOOK (STUFF) values (?)' with: #('Better Now'). - db commitTransaction. - + db commitTransaction. + rows := (db execute: 'select last_insert_rowid() as lid') rows. self assert: (rows first at: 'lid') equals: 2. - + rows := (db execute: 'select * from BOOK') rows. self assert: rows size equals: 2. self assert: (rows first at: 'ID') equals: 1. - self assert: (rows first at: 'STUFF') equals: 'The Bad Beginning'. - - + self assert: (rows first at: 'STUFF') equals: 'The Bad Beginning' ] { #category : #'tests - glorp compatibility' } SQLite3ConnectionTest >> testGlorpCompositeKey [ | schema rows | - + "This is the schema generated by Glorp." schema := 'CREATE TABLE GR_USER (ID integer NOT NULL ,NAME text NULL , CONSTRAINT GR_USER_PK PRIMARY KEY (ID), CONSTRAINT GR_USER_UNIQ UNIQUE (ID));'. - + db basicExecute: schema. db beginTransaction. db execute: 'insert into GR_USER values (?, ?)' with: #(1 'User One'). db execute: 'insert into GR_USER values (?, ?)' with: #(2 'User Two'). - db commitTransaction. - + db commitTransaction. + rs := db execute: 'select ID,NAME from GR_USER'. rows := rs rows. - + self assert: rows size equals: 2. self assert: (rows first at: 'ID') equals: 1. self assert: (rows first at: 'NAME') equals: 'User One' - ] { #category : #'tests - glorp compatibility' } SQLite3ConnectionTest >> testGlorpDoubleInsertPrimaryKey [ | schema rows | - + schema := 'CREATE TABLE GR_USER (ID integer NOT NULL ,NAME text NULL , CONSTRAINT GR_USER_PK PRIMARY KEY (ID), CONSTRAINT GR_USER_UNIQ UNIQUE (ID));'. - + db basicExecute: schema. db beginTransaction. - db execute: 'insert into GR_USER values (?, ?)' + db execute: 'insert into GR_USER values (?, ?)' with: #(1 'Fred'). self should: [ db execute: 'insert into GR_USER values (?, ?)' with: #(1 'Barney') ] raise: SQLite3AbstractError. - db commitTransaction. - + db commitTransaction. + rs := db execute: 'select * from GR_USER'. rows := rs rows. - + self assert: rows size equals: 1. self assert: (rows first at: 'ID') equals: 1. - self assert: (rows first at: 'NAME') equals: 'Fred'. - - + self assert: (rows first at: 'NAME') equals: 'Fred' ] { #category : #'tests - glorp compatibility' } SQLite3ConnectionTest >> testGlorpUpdate [ | schema rows | - + schema := 'CREATE TABLE BOOK (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,TITLE text NULL ,DESCRIPTION text NULL ,COPIES_IN_STOCK int NULL ,VERSION int NULL );'. - + db basicExecute: schema. db beginTransaction. - db execute: 'insert into BOOK (TITLE,COPIES_IN_STOCK,VERSION) values (?, ?, ?)' + db execute: 'insert into BOOK (TITLE,COPIES_IN_STOCK,VERSION) values (?, ?, ?)' with: #('The Bad Beginning' 3 6). db execute: 'UPDATE BOOK SET TITLE = ?,COPIES_IN_STOCK = ?,VERSION = ? WHERE ID = ? AND BOOK.VERSION = ?' with: #('The Bad Beginning' 6 7 1 6). - db commitTransaction. - + db commitTransaction. + rs := db execute: 'select * from BOOK'. rows := rs rows. - + self assert: rows size equals: 1. self assert: (rows first at: 'ID') equals: 1. self assert: (rows first at: 'TITLE') equals: 'The Bad Beginning'. @@ -970,21 +950,21 @@ SQLite3ConnectionTest >> testGlorpUpdate [ { #category : #'tests - glorp compatibility' } SQLite3ConnectionTest >> testGlorpUpdateTwice [ | schema rows | - + schema := 'CREATE TABLE BOOK (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,TITLE text NULL ,DESCRIPTION text NULL ,COPIES_IN_STOCK int NULL ,VERSION int NULL );'. - + db basicExecute: schema. db beginTransaction. - db execute: 'insert into BOOK (TITLE,COPIES_IN_STOCK,VERSION) values (?, ?, ?)' + db execute: 'insert into BOOK (TITLE,COPIES_IN_STOCK,VERSION) values (?, ?, ?)' with: #('The Bad Beginning' 3 6). db execute: 'UPDATE BOOK SET COPIES_IN_STOCK = 7'. db execute: 'UPDATE BOOK SET TITLE = ?,COPIES_IN_STOCK = ?,VERSION = ? WHERE ID = ? AND BOOK.VERSION = ?' with: #('The Bad Beginning' 6 7 1 6). - db commitTransaction. - + db commitTransaction. + rs := db execute: 'select * from BOOK'. rows := rs rows. - + self assert: rows size equals: 1. self assert: (rows first at: 'ID') equals: 1. self assert: (rows first at: 'TITLE') equals: 'The Bad Beginning'. @@ -1031,7 +1011,7 @@ SQLite3ConnectionTest >> testRows [ self assert: ( rows first at: 1 ) equals: 1. self assert: ( rows first at: 3 ) equals: '1-ZZZ'. - 1 to: 5 do: [ :x | + 1 to: 5 do: [ :x | any := Random new nextInt: rowCount. self assert: ( ( rows at: any ) at: 'rk' ) equals: any. self assert: ( ( rows at: any ) at: 'rt' ) equals: any asString , '-ZZZ'. @@ -1049,12 +1029,12 @@ SQLite3ConnectionTest >> testRows [ SQLite3ConnectionTest >> testStatementReadOnly [ | stmt | - + self populateRowsInto: 'junk' of: db. stmt := db prepare: 'select * from junk'. self assert: stmt isReadOnly equals: true. stmt := db prepare: 'delete from junk'. - self assert: stmt isReadOnly equals: false. + self assert: stmt isReadOnly equals: false ] { #category : #tests } @@ -1083,11 +1063,11 @@ SQLite3ConnectionTest >> testValueInsertThenSelectInTransaction [ SQLite3ConnectionTest >> untestStatementInProgress [ "XXX Doesn't work yet." | s1 s2 | - + res := db basicExecute: 'create table if not exists x (xk integer primary key, iv integer);'. self assert: res equals: 0. - - + + db beginTransaction. s1 := db prepare: 'insert into x values (NULL, ?)'. s1 at: 1 putInteger: 1. @@ -1099,8 +1079,4 @@ SQLite3ConnectionTest >> untestStatementInProgress [ s1 reset. s1 finalize - - - - ] diff --git a/src/SQLite3-Core-Tests/SQLite3RowTest.class.st b/src/SQLite3-Core-Tests/SQLite3RowTest.class.st index 4eb173c..f131aa8 100644 --- a/src/SQLite3-Core-Tests/SQLite3RowTest.class.st +++ b/src/SQLite3-Core-Tests/SQLite3RowTest.class.st @@ -25,7 +25,7 @@ SQLite3RowTest >> setUp [ { #category : #tests } SQLite3RowTest >> testAsArray [ - self assert: emptyRow asArray equals: #(). + self assert: emptyRow asArray equals: #(). self assert: filledRow asArray equals: #(1 true '3.14') ] @@ -38,8 +38,8 @@ SQLite3RowTest >> testAsCombinedDictionary [ dict at: 'pi' put: '3.14'. dict at: 1 put: 1. dict at: 2 put: true. - dict at: 3 put: '3.14'. - self assert: emptyRow asCombinedDictionary equals: Dictionary new. + dict at: 3 put: '3.14'. + self assert: emptyRow asCombinedDictionary equals: Dictionary new. self assert: filledRow asCombinedDictionary equals: dict ] @@ -50,8 +50,8 @@ SQLite3RowTest >> testAsDictionary [ dict at: 'foo' put: 1. dict at: 'bar' put: true. dict at: 'pi' put: '3.14'. - - self assert: emptyRow asDictionary equals: Dictionary new. + + self assert: emptyRow asDictionary equals: Dictionary new. self assert: filledRow asDictionary equals: dict ] @@ -59,14 +59,14 @@ SQLite3RowTest >> testAsDictionary [ SQLite3RowTest >> testColumnAccessingIfAbsent [ |blockExecutedFlag| blockExecutedFlag := false. - + filledRow at: 'foo' ifAbsent: [ blockExecutedFlag := true ]. - + self deny: blockExecutedFlag. - + filledRow at: 'nope' ifAbsent: [ blockExecutedFlag := true ]. - - self assert: blockExecutedFlag. + + self assert: blockExecutedFlag ] { #category : #tests } @@ -81,39 +81,38 @@ SQLite3RowTest >> testColumnAccessingOnFilledRow [ self assert: (filledRow at: 'foo') equals: 1. self assert: (filledRow at: 'bar') equals: true. self assert: (filledRow at: 'pi') equals: '3.14'. - + self assert: (filledRow at: 'nope') equals: nil ] { #category : #tests } SQLite3RowTest >> testColumnNamesOnEmptyRow [ - self assert: emptyRow columnNames equals: #() + self assert: emptyRow columnNames equals: #() ] { #category : #tests } SQLite3RowTest >> testColumnNamesOnFilledRow [ - + self assert: filledRow columnNames equals: #('foo' 'bar' 'pi') ] { #category : #tests } SQLite3RowTest >> testColumnPuttingOnEmptyRow [ - + self assert: (emptyRow at: 'foo') equals: nil. - + emptyRow at: 'foo' put: 42. - - self assert: (emptyRow at: 'foo') equals: 42. + self assert: (emptyRow at: 'foo') equals: 42 ] { #category : #tests } SQLite3RowTest >> testColumnPuttingOnFilledRow [ - + self assert: (filledRow at: 'foo') equals: 1. - + filledRow at: 'foo' put: 2. - + self assert: (filledRow at: 'foo') equals: 2 ] diff --git a/src/SQLite3-Core-Tests/SQLite3TableTest.class.st b/src/SQLite3-Core-Tests/SQLite3TableTest.class.st index 5b33625..b9a6668 100644 --- a/src/SQLite3-Core-Tests/SQLite3TableTest.class.st +++ b/src/SQLite3-Core-Tests/SQLite3TableTest.class.st @@ -31,10 +31,10 @@ SQLite3TableTest >> tableCreationScript [ ] { #category : #running } -SQLite3TableTest >> tearDown [ +SQLite3TableTest >> tearDown [ db connection close. db := nil. - super tearDown + super tearDown ] { #category : #tests } @@ -127,12 +127,12 @@ SQLite3TableTest >> testSampleTableProperties [ |props| props := table properties. self assert: props size equals: 5. - + self assert: (props at: #type) equals: 'table'. self assert: (props at: #tbl_name) equals: 'SAMPLE'. self assert: (props at: #rootpage) equals: 2. self assert: (props at: #name) equals: 'SAMPLE'. - self assert: (props at: #sql) equals: self tableCreationScript + self assert: (props at: #sql) equals: self tableCreationScript ] { #category : #'tests - sample' } @@ -142,8 +142,7 @@ SQLite3TableTest >> testSampleTableSchema [ ] { #category : #tests } -SQLite3TableTest >> testUnitializedName [ +SQLite3TableTest >> testUnitializedName [ self assert: SQLite3Table new name equals: '' - ] From 1126d59cd948227f3d256606da21479f68cc69ab Mon Sep 17 00:00:00 2001 From: Torsten Bergmann Date: Sun, 17 Sep 2023 21:54:18 +0200 Subject: [PATCH 3/5] Fix and review SQLite3-Core-Benchmarks --- .../SQLite3Benchmark.class.st | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/SQLite3-Core-Benchmarks/SQLite3Benchmark.class.st b/src/SQLite3-Core-Benchmarks/SQLite3Benchmark.class.st index 9b333ed..d7fa1df 100644 --- a/src/SQLite3-Core-Benchmarks/SQLite3Benchmark.class.st +++ b/src/SQLite3-Core-Benchmarks/SQLite3Benchmark.class.st @@ -13,13 +13,11 @@ Class { { #category : #running } SQLite3Benchmark >> basicExecute: anSQLText times: aCount [ - + db beginTransaction. 1 to: aCount do: [ :i | db basicExecute: anSQLText ]. - db commitTransaction. - - + db commitTransaction ] { #category : #'connecting-disconnecting' } @@ -34,41 +32,33 @@ SQLite3Benchmark >> disconnect [ { #category : #running } SQLite3Benchmark >> execute: anSQLText times: aCount bindingsBlock: bindingsBlock [ - + db beginTransaction. 1 to: aCount do: [ :i | db execute: anSQLText with: (bindingsBlock value: i) ]. - db commitTransaction. - - + db commitTransaction ] { #category : #running } SQLite3Benchmark >> finalizeStatement [ stmt ifNotNil: [ stmt finalize ] - - ] { #category : #running } SQLite3Benchmark >> prepStep: anSQLText times: aCount bindingsBlock: bindingsBlock [ - + stmt := db prepare: anSQLText. db beginTransaction. 1 to: aCount do: [ :i | bindingsBlock value: stmt value: i. stmt step; clearBindings; reset ]. - db commitTransaction. - - + db commitTransaction ] { #category : #running } SQLite3Benchmark >> runBlock: aBlock [ - + db beginTransaction. aBlock value: db. - db commitTransaction. - - + db commitTransaction ] From 6fe0024d37e06a898025329a232c2da2348d9e19 Mon Sep 17 00:00:00 2001 From: Torsten Bergmann Date: Sun, 17 Sep 2023 22:09:17 +0200 Subject: [PATCH 4/5] Fix and review SQLite3-Core --- src/SQLite3-Core/SQLite3Abort.class.st | 4 +- .../SQLite3AbstractError.class.st | 2 +- .../SQLite3AuthorizationDenied.class.st | 2 +- src/SQLite3-Core/SQLite3Backup.class.st | 12 +- .../SQLite3BackupExternalReference.class.st | 2 +- .../SQLite3BaseConnection.class.st | 72 ++--- src/SQLite3-Core/SQLite3Busy.class.st | 4 +- src/SQLite3-Core/SQLite3Column.class.st | 6 +- src/SQLite3-Core/SQLite3Connection.class.st | 15 +- src/SQLite3-Core/SQLite3Constants.class.st | 49 ++- .../SQLite3ConstraintViolation.class.st | 2 +- .../SQLite3ConstraintViolationUnique.class.st | 2 +- ...e3ConstraintViolationVirtualTable.class.st | 2 +- src/SQLite3-Core/SQLite3Cursor.class.st | 26 +- src/SQLite3-Core/SQLite3Database.class.st | 16 +- src/SQLite3-Core/SQLite3Error.class.st | 2 +- src/SQLite3-Core/SQLite3Full.class.st | 2 +- .../SQLite3IOErrorAccess.class.st | 2 +- .../SQLite3IOErrorBlocked.class.st | 2 +- .../SQLite3IOErrorCheckReservedLock.class.st | 2 +- src/SQLite3-Core/SQLite3IOErrorClose.class.st | 2 +- .../SQLite3IOErrorConvertPath.class.st | 2 +- .../SQLite3IOErrorDelete.class.st | 2 +- .../SQLite3IOErrorDirFSync.class.st | 2 +- src/SQLite3-Core/SQLite3IOErrorFSync.class.st | 2 +- src/SQLite3-Core/SQLite3IOErrorLock.class.st | 2 +- .../SQLite3IOErrorNoMemory.class.st | 2 +- src/SQLite3-Core/SQLite3IOErrorRead.class.st | 2 +- src/SQLite3-Core/SQLite3IOErrorSeek.class.st | 2 +- .../SQLite3IOErrorSharedMemoryOpen.class.st | 2 +- .../SQLite3IOErrorSharedMemorySize.class.st | 2 +- .../SQLite3IOErrorShortRead.class.st | 2 +- .../SQLite3IOErrorUnlock.class.st | 2 +- src/SQLite3-Core/SQLite3IOErrorWrite.class.st | 2 +- src/SQLite3-Core/SQLite3Internal.class.st | 2 +- src/SQLite3-Core/SQLite3Library.class.st | 300 +++++++----------- src/SQLite3-Core/SQLite3Locked.class.st | 4 +- src/SQLite3-Core/SQLite3Misuse.class.st | 4 +- src/SQLite3-Core/SQLite3NativeError.class.st | 8 +- .../SQLite3PreparedStatement.class.st | 72 ++--- src/SQLite3-Core/SQLite3Result.class.st | 6 +- src/SQLite3-Core/SQLite3Row.class.st | 30 +- src/SQLite3-Core/SQLite3Table.class.st | 5 +- 43 files changed, 278 insertions(+), 407 deletions(-) diff --git a/src/SQLite3-Core/SQLite3Abort.class.st b/src/SQLite3-Core/SQLite3Abort.class.st index a8860d7..d847e65 100644 --- a/src/SQLite3-Core/SQLite3Abort.class.st +++ b/src/SQLite3-Core/SQLite3Abort.class.st @@ -16,7 +16,7 @@ Class { } { #category : #'private - accessing' } -SQLite3Abort class >> nativeErrorCode [ - +SQLite3Abort class >> nativeErrorCode [ + ^ SQLITE_ABORT ] diff --git a/src/SQLite3-Core/SQLite3AbstractError.class.st b/src/SQLite3-Core/SQLite3AbstractError.class.st index 5060d04..819572c 100644 --- a/src/SQLite3-Core/SQLite3AbstractError.class.st +++ b/src/SQLite3-Core/SQLite3AbstractError.class.st @@ -11,7 +11,7 @@ Class { } { #category : #testing } -SQLite3AbstractError class >> isAbstract [ +SQLite3AbstractError class >> isAbstract [ ^self name = #SQLite3AbstractError ] diff --git a/src/SQLite3-Core/SQLite3AuthorizationDenied.class.st b/src/SQLite3-Core/SQLite3AuthorizationDenied.class.st index 5fed306..12e4c58 100644 --- a/src/SQLite3-Core/SQLite3AuthorizationDenied.class.st +++ b/src/SQLite3-Core/SQLite3AuthorizationDenied.class.st @@ -11,6 +11,6 @@ Class { { #category : #'private - accessing' } SQLite3AuthorizationDenied class >> nativeErrorCode [ - + ^ SQLITE_AUTH ] diff --git a/src/SQLite3-Core/SQLite3Backup.class.st b/src/SQLite3-Core/SQLite3Backup.class.st index b75a103..cb5ebd7 100644 --- a/src/SQLite3-Core/SQLite3Backup.class.st +++ b/src/SQLite3-Core/SQLite3Backup.class.st @@ -48,13 +48,13 @@ SQLite3Backup >> dstName: anObject [ ] { #category : #finalization } -SQLite3Backup >> finalize [ +SQLite3Backup >> finalize [ self finish ] { #category : #initialization } -SQLite3Backup >> finish [ - handle +SQLite3Backup >> finish [ + handle ifNotNil: [ library apiBackupFinish: handle. handle beNull. @@ -77,7 +77,7 @@ SQLite3Backup >> initialize [ isOpen := false. library := SQLite3Library current. handle := SQLite3DatabaseExternalObject new. - handle autoRelease. + handle autoRelease ] { #category : #accessing } @@ -86,7 +86,7 @@ SQLite3Backup >> isOpen [ ] { #category : #accessing } -SQLite3Backup >> open [ +SQLite3Backup >> open [ handle := (library backupTo: dstConnection named: dstName from: srcConnection named: srcName). isOpen := true ] @@ -112,7 +112,7 @@ SQLite3Backup >> srcName: anObject [ ] { #category : #accessing } -SQLite3Backup >> step [ +SQLite3Backup >> step [ "Passing negative number means run to completion" self step: -1 ] diff --git a/src/SQLite3-Core/SQLite3BackupExternalReference.class.st b/src/SQLite3-Core/SQLite3BackupExternalReference.class.st index edf276e..2b961b5 100644 --- a/src/SQLite3-Core/SQLite3BackupExternalReference.class.st +++ b/src/SQLite3-Core/SQLite3BackupExternalReference.class.st @@ -9,6 +9,6 @@ Class { { #category : #initialization } SQLite3BackupExternalReference >> beNull [ - + ^ handle beNull ] diff --git a/src/SQLite3-Core/SQLite3BaseConnection.class.st b/src/SQLite3-Core/SQLite3BaseConnection.class.st index fb9e972..2a99b80 100644 --- a/src/SQLite3-Core/SQLite3BaseConnection.class.st +++ b/src/SQLite3-Core/SQLite3BaseConnection.class.st @@ -25,14 +25,14 @@ SQLite3BaseConnection class >> isAbstract [ { #category : #testing } SQLite3BaseConnection class >> isThreadsafe [ "Native Library Version http://sqlite.org/c3ref/libversion.html sqlite3_libversion" - - ^ SQLite3Library current isThreadsafe ~= 0 + + ^ SQLite3Library current isThreadsafe ~= 0 ] { #category : #accessing } SQLite3BaseConnection class >> libraryVersion [ "Native Library Version http://sqlite.org/c3ref/libversion.html sqlite3_libversion" - + ^ SQLite3Library current libraryVersion ] @@ -45,29 +45,27 @@ SQLite3BaseConnection class >> memory [ { #category : #'instance creation' } SQLite3BaseConnection class >> on: aFilename [ - ^(self new) + ^(self new) on: aFilename; yourself - ] { #category : #'instance creation' } SQLite3BaseConnection class >> openOn: aFilename [ - ^(self new) - on: aFilename; - open; + ^(self new) + on: aFilename; + open; yourself - ] { #category : #testing } -SQLite3BaseConnection class >> threadsafe [ +SQLite3BaseConnection class >> threadsafe [ "This method is deprecated so consider to migrate." - self deprecated: 'Please use #isThreadsafe instead' transformWith: '`@receiver threadsafe' + self deprecated: 'Please use #isThreadsafe instead' transformWith: '`@receiver threadsafe' -> '`@receiver isThreadsafe'. - - ^ self isThreadsafe + + ^ self isThreadsafe ] { #category : #'public API - backups' } @@ -90,16 +88,15 @@ SQLite3BaseConnection >> backupTo: aConnection named: aName [ ] { #category : #'public API - operating' } -SQLite3BaseConnection >> basicExecute: anSQLText [ +SQLite3BaseConnection >> basicExecute: anSQLText [ ^ (self prepare: anSQLText) step; finalize "20190302, pierce: This used to invoke sqlite3_exec() which is an SQLite-internal convenience wrapper around prepare/step/finalize. It is now rewritten as seen to handle UTF8-encoded input properly. Rewriting this method breaks the Bobby Tables test which relies on naive SQL string construction to work." - ] { #category : #'public API - transactional' } SQLite3BaseConnection >> beginTransaction [ - ^ self basicExecute: 'begin' + ^ self basicExecute: 'begin' ] { #category : #'public API - introspection' } @@ -110,7 +107,6 @@ SQLite3BaseConnection >> changes [ { #category : #'public API - operating' } SQLite3BaseConnection >> clearBindings: aStatement [ library clearBindings: aStatement handle on: dbHandle - ] { #category : #'public API - open/close' } @@ -126,16 +122,16 @@ SQLite3BaseConnection >> close [ { #category : #'public API - introspection' } SQLite3BaseConnection >> columnNamesFor: aTableName [ - + self isOpen ifFalse: [ SQLite3NotOpen signal ] - ifTrue: [ + ifTrue: [ | s tableExists | s := self prepare: 'select count(*) from sqlite_master where type = "table" and tbl_name = ?'. s at: 1 putString: aTableName. s basicExecute: [ :row | tableExists := ((row integerAt: 0) = 1) ]. s finalize. - tableExists ifTrue: [ + tableExists ifTrue: [ | columns | columns := OrderedCollection new. s := self prepare: 'pragma table_info(', aTableName, ')'. @@ -143,26 +139,25 @@ SQLite3BaseConnection >> columnNamesFor: aTableName [ s finalize. ^ columns ]. ^ nil ] - ] { #category : #'public API - transactional' } SQLite3BaseConnection >> commitTransaction [ - ^ self basicExecute: 'commit' + ^ self basicExecute: 'commit' ] { #category : #'public API - introspection' } SQLite3BaseConnection >> declaredColumnTypesFor: aTableName [ - + self isOpen ifFalse: [ SQLite3NotOpen signal ] - ifTrue: [ + ifTrue: [ | s tableExists | s := self prepare: 'select count(*) from sqlite_master where type = "table" and tbl_name = ?'. s at: 1 putString: aTableName. s basicExecute: [ :row | tableExists := ((row integerAt: 0) = 1) ]. s finalize. - tableExists ifTrue: [ + tableExists ifTrue: [ | columns | columns := OrderedCollection new. s := self prepare: 'pragma table_info(', aTableName, ')'. @@ -170,22 +165,21 @@ SQLite3BaseConnection >> declaredColumnTypesFor: aTableName [ s finalize. ^ columns ]. ^ nil ] - ] { #category : #'public API - extensions' } SQLite3BaseConnection >> disableExtensions [ - ^ library disableLoadExtension: dbHandle + ^ library disableLoadExtension: dbHandle ] { #category : #'public API - extensions' } SQLite3BaseConnection >> enableExtensions [ - ^ library enableLoadExtension: dbHandle + ^ library enableLoadExtension: dbHandle ] { #category : #accessing } SQLite3BaseConnection >> filename [ - ^ dbFilename + ^ dbFilename ] { #category : #'public API - operating' } @@ -211,9 +205,7 @@ SQLite3BaseConnection >> initialize [ library := SQLite3Library current. dbHandle := SQLite3DatabaseExternalObject new. dbHandle autoRelease. - statementClass := SQLite3PreparedStatement. - - + statementClass := SQLite3PreparedStatement ] { #category : #testing } @@ -223,7 +215,7 @@ SQLite3BaseConnection >> isOpen [ { #category : #'public API - extensions' } SQLite3BaseConnection >> loadExtension: aFilename [ - ^ library loadExtension: dbHandle with: aFilename + ^ library loadExtension: dbHandle with: aFilename ] { #category : #private } @@ -240,25 +232,23 @@ SQLite3BaseConnection >> open [ ] { #category : #'public API - operating' } -SQLite3BaseConnection >> prepare: anSQLText [ +SQLite3BaseConnection >> prepare: anSQLText [ | s | - + s := self statementClass new. s connection: self. s prepare: anSQLText. ^ s - ] { #category : #'public API - cleaning' } -SQLite3BaseConnection >> reset: aStatement [ +SQLite3BaseConnection >> reset: aStatement [ ^library reset: aStatement handle - ] { #category : #'public API - transactional' } SQLite3BaseConnection >> rollbackTransaction [ - ^ self basicExecute: 'rollback' + ^ self basicExecute: 'rollback' ] { #category : #private } @@ -274,10 +264,10 @@ SQLite3BaseConnection >> statementClass [ { #category : #'public API - introspection' } SQLite3BaseConnection >> tableNames [ | tables s | - + self isOpen ifFalse: [ SQLite3NotOpen signal ] - ifTrue: [ + ifTrue: [ tables := OrderedCollection new. s := self prepare: 'select tbl_name from sqlite_master where type = "table"'. s basicExecute: [ :row | diff --git a/src/SQLite3-Core/SQLite3Busy.class.st b/src/SQLite3-Core/SQLite3Busy.class.st index 6deb141..d3b36a9 100644 --- a/src/SQLite3-Core/SQLite3Busy.class.st +++ b/src/SQLite3-Core/SQLite3Busy.class.st @@ -18,7 +18,7 @@ Class { } { #category : #'private - accessing' } -SQLite3Busy class >> nativeErrorCode [ - +SQLite3Busy class >> nativeErrorCode [ + ^ SQLITE_BUSY ] diff --git a/src/SQLite3-Core/SQLite3Column.class.st b/src/SQLite3-Core/SQLite3Column.class.st index ae87923..a05329b 100644 --- a/src/SQLite3-Core/SQLite3Column.class.st +++ b/src/SQLite3-Core/SQLite3Column.class.st @@ -14,8 +14,8 @@ Class { } { #category : #'instance creation' } -SQLite3Column class >> readFromTableInfoResult: aSQLite3Row [ - +SQLite3Column class >> readFromTableInfoResult: aSQLite3Row [ + ^(self new) name: (aSQLite3Row at: 'name'); index: (aSQLite3Row at: 'cid'); @@ -49,7 +49,7 @@ SQLite3Column >> index: anObject [ ] { #category : #initialization } -SQLite3Column >> initialize [ +SQLite3Column >> initialize [ super initialize. hasNotNullConstraint := false diff --git a/src/SQLite3-Core/SQLite3Connection.class.st b/src/SQLite3-Core/SQLite3Connection.class.st index f773337..b868b30 100644 --- a/src/SQLite3-Core/SQLite3Connection.class.st +++ b/src/SQLite3-Core/SQLite3Connection.class.st @@ -9,40 +9,35 @@ Class { } { #category : #'public API - operating' } -SQLite3Connection >> execute: anSQLText [ +SQLite3Connection >> execute: anSQLText [ ^ self execute: anSQLText with: #() ] { #category : #'public API - operating' } SQLite3Connection >> execute: anSQLText value: anObject [ ^ (self prepare: anSQLText) execute: (Array with: anObject) - ] { #category : #'public API - operating' } SQLite3Connection >> execute: anSQLText value: object1 value: object2 [ ^ self execute: anSQLText with: (Array with: object1 with: object2) - ] { #category : #'public API - operating' } SQLite3Connection >> execute: anSQLText value: object1 value: object2 value: object3 [ - ^ self execute: anSQLText - with: (Array with: object1 with: object2 with: object3) - + ^ self execute: anSQLText + with: (Array with: object1 with: object2 with: object3) ] { #category : #'public API - operating' } SQLite3Connection >> execute: anSQLText value: object1 value: object2 value: object3 value: object4 [ - ^ self execute: anSQLText - with: (Array with: object1 with: object2 with: object3 with: object4) - + ^ self execute: anSQLText + with: (Array with: object1 with: object2 with: object3 with: object4) ] { #category : #'public API - operating' } SQLite3Connection >> execute: anSQLText with: aCollection [ ^(self prepare: anSQLText) execute: aCollection - ] { #category : #'public API - operating' } diff --git a/src/SQLite3-Core/SQLite3Constants.class.st b/src/SQLite3-Core/SQLite3Constants.class.st index 1f527d8..90992c5 100644 --- a/src/SQLite3-Core/SQLite3Constants.class.st +++ b/src/SQLite3-Core/SQLite3Constants.class.st @@ -143,67 +143,60 @@ SQLite3Constants class >> initCheckpointModes [ SQLITE_CHECKPOINT_PASSIVE := 0. SQLITE_CHECKPOINT_FULL := 1. SQLITE_CHECKPOINT_RESTART := 2. - SQLITE_CHECKPOINT_TRUNCATE := 3. - - + SQLITE_CHECKPOINT_TRUNCATE := 3 ] { #category : #'private - initialization' } SQLite3Constants class >> initConstants [ - - self - initResultCodes; + + self + initResultCodes; initErrorCodes; initExtendedErrorCodes; initFileOpenFlags - - - ] { #category : #'private - initialization' } SQLite3Constants class >> initDataTypes [ "Fundamental Datatypes" - + SQLITE_INTEGER := 1. SQLITE_FLOAT := 2. SQLITE_TEXT := 3. SQLITE3_TEXT := 3. - SQLITE_BLOB := 4. + SQLITE_BLOB := 4. SQLITE_NULL := 5 - - ] { #category : #'private - initialization constants' } SQLite3Constants class >> initErrorCodes [ - "In its default configuration, SQLite API routines return one of 26 integer + "In its default configuration, SQLite API routines return one of 26 integer [SQLITE_OK | result codes]." SQLITE_ERROR := 1. "SQL error or missing database" SQLITE_INTERNAL := 2. "Internal logic error in SQLite" - SQLITE_PERM := 3. "Access permission denied" - SQLITE_ABORT := 4. "Callback routine requested an abort" - SQLITE_BUSY := 5. "The database file is locked" + SQLITE_PERM := 3. "Access permission denied" + SQLITE_ABORT := 4. "Callback routine requested an abort" + SQLITE_BUSY := 5. "The database file is locked" SQLITE_LOCKED := 6. "A table in the database is locked" SQLITE_NOMEM := 7. "A malloc() failed" SQLITE_READONLY := 8. "Attempt to write a readonly database" SQLITE_INTERRUPT := 9. "Operation terminated by sqlite3_interrupt()" SQLITE_IOERR := 10. "Some kind of disk I/O error occurred" SQLITE_CORRUPT := 11. "The database disk image is malformed" - SQLITE_NOTFOUND := 12. "Unknown opcode in sqlite3_file_control()" - SQLITE_FULL := 13. "Insertion failed because database is full" + SQLITE_NOTFOUND := 12. "Unknown opcode in sqlite3_file_control()" + SQLITE_FULL := 13. "Insertion failed because database is full" SQLITE_CANTOPEN := 14. "Unable to open the database file" SQLITE_PROTOCOL := 15. "Database lock protocol error" SQLITE_EMPTY := 16. "Database is empty" SQLITE_SCHEMA := 17. "The database schema changed" - SQLITE_TOOBIG := 18. "String or BLOB exceeds size limit" + SQLITE_TOOBIG := 18. "String or BLOB exceeds size limit" SQLITE_CONSTRAINT := 19. "Abort due to constraint violation" - SQLITE_MISMATCH := 20. "Data type mismatch" + SQLITE_MISMATCH := 20. "Data type mismatch" SQLITE_MISUSE := 21. "Library used incorrectly" - SQLITE_NOLFS := 22. "Uses OS features not supported on host" - SQLITE_AUTH := 23. "Authorization denied" - SQLITE_FORMAT := 24. "Auxiliary database format error" + SQLITE_NOLFS := 22. "Uses OS features not supported on host" + SQLITE_AUTH := 23. "Authorization denied" + SQLITE_FORMAT := 24. "Auxiliary database format error" SQLITE_RANGE := 25. "2nd parameter to sqlite3_bind out of range" SQLITE_NOTADB := 26. "File opened that is not a database file" SQLITE_NOTICE := 27. "Notifications from sqlite3_log()" @@ -280,7 +273,7 @@ SQLite3Constants class >> initExtendedErrorCodes [ SQLITE_NOTICE_RECOVER_ROLLBACK := (SQLITE_NOTICE | (2<<8)). SQLITE_WARNING_AUTOINDEX := (SQLITE_WARNING | (1<<8)). SQLITE_AUTH_USER := (SQLITE_AUTH | (1<<8)). - SQLITE_OK_LOAD_PERMANENTLY := (SQLITE_OK | (1<<8)). + SQLITE_OK_LOAD_PERMANENTLY := (SQLITE_OK | (1<<8)) ] { #category : #'private - initialization constants' } @@ -318,10 +311,8 @@ SQLite3Constants class >> initResultCodes [ { #category : #initialization } SQLite3Constants class >> initialize [ - self + self initConstants; initDataTypes; - initCheckpointModes - - + initCheckpointModes ] diff --git a/src/SQLite3-Core/SQLite3ConstraintViolation.class.st b/src/SQLite3-Core/SQLite3ConstraintViolation.class.st index 140f14e..2258c36 100644 --- a/src/SQLite3-Core/SQLite3ConstraintViolation.class.st +++ b/src/SQLite3-Core/SQLite3ConstraintViolation.class.st @@ -11,6 +11,6 @@ Class { { #category : #'private - accessing' } SQLite3ConstraintViolation class >> nativeErrorCode [ - + ^ SQLITE_CONSTRAINT ] diff --git a/src/SQLite3-Core/SQLite3ConstraintViolationUnique.class.st b/src/SQLite3-Core/SQLite3ConstraintViolationUnique.class.st index 0a23274..c255983 100644 --- a/src/SQLite3-Core/SQLite3ConstraintViolationUnique.class.st +++ b/src/SQLite3-Core/SQLite3ConstraintViolationUnique.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3ConstraintViolationUnique class >> nativeErrorCode [ +SQLite3ConstraintViolationUnique class >> nativeErrorCode [ ^ SQLITE_CONSTRAINT_UNIQUE ] diff --git a/src/SQLite3-Core/SQLite3ConstraintViolationVirtualTable.class.st b/src/SQLite3-Core/SQLite3ConstraintViolationVirtualTable.class.st index f20dbc7..74a4771 100644 --- a/src/SQLite3-Core/SQLite3ConstraintViolationVirtualTable.class.st +++ b/src/SQLite3-Core/SQLite3ConstraintViolationVirtualTable.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3ConstraintViolationVirtualTable class >> nativeErrorCode [ +SQLite3ConstraintViolationVirtualTable class >> nativeErrorCode [ ^ SQLITE_CONSTRAINT_VTAB ] diff --git a/src/SQLite3-Core/SQLite3Cursor.class.st b/src/SQLite3-Core/SQLite3Cursor.class.st index 768dd77..477662f 100644 --- a/src/SQLite3-Core/SQLite3Cursor.class.st +++ b/src/SQLite3-Core/SQLite3Cursor.class.st @@ -19,8 +19,8 @@ Class { } { #category : #'instance creation' } -SQLite3Cursor class >> on: aStatement [ - ^(self new) statement: aStatement; yourself. +SQLite3Cursor class >> on: aStatement [ + ^(self new) statement: aStatement; yourself ] { #category : #accessing } @@ -33,7 +33,7 @@ SQLite3Cursor >> close [ " closing a cursor is not the same as closing the statement - we may reuse a prepared statement" statement ifNotNil: [ statement reset ]. statement := nil. - mutators := nil. + mutators := nil ] { #category : #accessing } @@ -42,7 +42,7 @@ SQLite3Cursor >> columnNames [ ] { #category : #accessing } -SQLite3Cursor >> connection [ +SQLite3Cursor >> connection [ ^statement connection ] @@ -54,18 +54,17 @@ SQLite3Cursor >> finalizeStatement [ { #category : #initialization } SQLite3Cursor >> initialize [ "Initializes the receiver" - + super initialize. moreRows := true. rowClass := SQLite3Row - ] { #category : #accessing } SQLite3Cursor >> mutators [ ^ mutators ifNil: [ mutators := self columnNames - collect: [ :c | + collect: [ :c | (((c substrings: ' _-()') collect: [ :ea | ea capitalized ]) joinUsing: '') uncapitalized asSymbol asMutator ] ] ] @@ -73,14 +72,13 @@ SQLite3Cursor >> mutators [ { #category : #API } SQLite3Cursor >> next [ ^ self nextOfClass: self rowClass - ] { #category : #API } SQLite3Cursor >> nextOfClass: aRowClass [ | rr | moreRows ifFalse: [ ^nil ]. - + statement ifNil: [ SQLite3Misuse signal: 'This result set does not contain a prepared statement.' ]. @@ -95,9 +93,9 @@ SQLite3Cursor >> nextOfClass: aRowClass [ ifFalse: [ | msgs | "custom object" msgs := self mutators. - 1 to: msgs size do: [ :c | + 1 to: msgs size do: [ :c | (rr respondsTo: (msgs at: c)) - ifTrue: [ rr perform: (msgs at: c) with: (statement valueOfColumn: c - 1) ] ] + ifTrue: [ rr perform: (msgs at: c) with: (statement valueOfColumn: c - 1) ] ] ]. moreRows := statement step = SQLITE_ROW. moreRows ifFalse: [ self close ]. @@ -110,7 +108,6 @@ SQLite3Cursor >> onlyRow [ ^ self onlyRow: [ ] "For the common case where there is exactly one row expected. Returns nil if there is no row." - ] { #category : #API } @@ -120,7 +117,6 @@ SQLite3Cursor >> onlyRow: ifNoneBlock [ ifNotEmpty: [ rows first ]. "For the common case where there is exactly one row expected. Returns the evaluation of ifNoneBlock if there is no row." - ] { #category : #API } @@ -141,17 +137,15 @@ SQLite3Cursor >> rowClass: anObject [ { #category : #API } SQLite3Cursor >> rows [ ^ self rowsOfClass: self rowClass - ] { #category : #API } SQLite3Cursor >> rowsOfClass: aRowClass [ - + rows ifNil: [ rows := OrderedCollection new ]. [ moreRows ] whileTrue: [ rows add: (self nextOfClass: aRowClass) ]. ^ rows - ] { #category : #accessing } diff --git a/src/SQLite3-Core/SQLite3Database.class.st b/src/SQLite3-Core/SQLite3Database.class.st index 5b12b66..16ebff4 100644 --- a/src/SQLite3-Core/SQLite3Database.class.st +++ b/src/SQLite3-Core/SQLite3Database.class.st @@ -13,7 +13,7 @@ Class { { #category : #'instance creation' } SQLite3Database class >> forConnection: aConnection [ - ^ self new + ^ self new initConnection: aConnection; yourself ] @@ -40,10 +40,10 @@ SQLite3Database class >> openOn: aFilename [ { #category : #accessing } SQLite3Database class >> tableInfoFor: aFileName [ - + | db | db := self on: aFileName. - db connection open. + db connection open. ^ db tables ] @@ -74,7 +74,7 @@ SQLite3Database >> execute: anSQLStatement doing: aBlock [ { #category : #'private - initialization' } SQLite3Database >> initConnection: aConnection [ - connection := aConnection + connection := aConnection ] { #category : #'open/close' } @@ -103,13 +103,13 @@ SQLite3Database >> tables [ SELECT * FROM sqlite_master WHERE - type =''table'' AND + type =''table'' AND name NOT LIKE ''sqlite_%'';' with: #( ) - doing: [ :result | - result rows collect: [ :eachRow | + doing: [ :result | + result rows collect: [ :eachRow | | properties | - properties := (eachRow columnNames collect: [ :eachCName | + properties := (eachRow columnNames collect: [ :eachCName | eachCName -> (eachRow atName: eachCName) ]) asDictionary. diff --git a/src/SQLite3-Core/SQLite3Error.class.st b/src/SQLite3-Core/SQLite3Error.class.st index 90f4176..fb9c7e2 100644 --- a/src/SQLite3-Core/SQLite3Error.class.st +++ b/src/SQLite3-Core/SQLite3Error.class.st @@ -11,6 +11,6 @@ Class { { #category : #'private - accessing' } SQLite3Error class >> nativeErrorCode [ - + ^ SQLITE_ERROR ] diff --git a/src/SQLite3-Core/SQLite3Full.class.st b/src/SQLite3-Core/SQLite3Full.class.st index 8a2492a..f872d76 100644 --- a/src/SQLite3-Core/SQLite3Full.class.st +++ b/src/SQLite3-Core/SQLite3Full.class.st @@ -13,6 +13,6 @@ Class { { #category : #'private - accessing' } SQLite3Full class >> nativeErrorCode [ - + ^ SQLITE_FULL ] diff --git a/src/SQLite3-Core/SQLite3IOErrorAccess.class.st b/src/SQLite3-Core/SQLite3IOErrorAccess.class.st index 4e55848..7e4d46b 100644 --- a/src/SQLite3-Core/SQLite3IOErrorAccess.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorAccess.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorAccess class >> nativeErrorCode [ +SQLite3IOErrorAccess class >> nativeErrorCode [ ^ SQLITE_IOERR_ACCESS ] diff --git a/src/SQLite3-Core/SQLite3IOErrorBlocked.class.st b/src/SQLite3-Core/SQLite3IOErrorBlocked.class.st index 7f77312..5ed2495 100644 --- a/src/SQLite3-Core/SQLite3IOErrorBlocked.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorBlocked.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorBlocked class >> nativeErrorCode [ +SQLite3IOErrorBlocked class >> nativeErrorCode [ ^ SQLITE_IOERR_BLOCKED ] diff --git a/src/SQLite3-Core/SQLite3IOErrorCheckReservedLock.class.st b/src/SQLite3-Core/SQLite3IOErrorCheckReservedLock.class.st index f4b03f2..95ae06d 100644 --- a/src/SQLite3-Core/SQLite3IOErrorCheckReservedLock.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorCheckReservedLock.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorCheckReservedLock class >> nativeErrorCode [ +SQLite3IOErrorCheckReservedLock class >> nativeErrorCode [ ^ SQLITE_IOERR_CHECKRESERVEDLOCK ] diff --git a/src/SQLite3-Core/SQLite3IOErrorClose.class.st b/src/SQLite3-Core/SQLite3IOErrorClose.class.st index 28c18d3..59daa14 100644 --- a/src/SQLite3-Core/SQLite3IOErrorClose.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorClose.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorClose class >> nativeErrorCode [ +SQLite3IOErrorClose class >> nativeErrorCode [ ^ SQLITE_IOERR_CLOSE ] diff --git a/src/SQLite3-Core/SQLite3IOErrorConvertPath.class.st b/src/SQLite3-Core/SQLite3IOErrorConvertPath.class.st index 825d2d9..750665e 100644 --- a/src/SQLite3-Core/SQLite3IOErrorConvertPath.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorConvertPath.class.st @@ -9,6 +9,6 @@ Class { { #category : #'private - accessing' } SQLite3IOErrorConvertPath class >> nativeErrorCode [ - + ^ SQLITE_IOERR_CONVPATH ] diff --git a/src/SQLite3-Core/SQLite3IOErrorDelete.class.st b/src/SQLite3-Core/SQLite3IOErrorDelete.class.st index d903222..58176b8 100644 --- a/src/SQLite3-Core/SQLite3IOErrorDelete.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorDelete.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorDelete class >> nativeErrorCode [ +SQLite3IOErrorDelete class >> nativeErrorCode [ ^ SQLITE_IOERR_DELETE ] diff --git a/src/SQLite3-Core/SQLite3IOErrorDirFSync.class.st b/src/SQLite3-Core/SQLite3IOErrorDirFSync.class.st index a6901eb..51b0617 100644 --- a/src/SQLite3-Core/SQLite3IOErrorDirFSync.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorDirFSync.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorDirFSync class >> nativeErrorCode [ +SQLite3IOErrorDirFSync class >> nativeErrorCode [ ^ SQLITE_IOERR_DIR_FSYNC ] diff --git a/src/SQLite3-Core/SQLite3IOErrorFSync.class.st b/src/SQLite3-Core/SQLite3IOErrorFSync.class.st index 0d11567..af1ce1b 100644 --- a/src/SQLite3-Core/SQLite3IOErrorFSync.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorFSync.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorFSync class >> nativeErrorCode [ +SQLite3IOErrorFSync class >> nativeErrorCode [ ^ SQLITE_IOERR_FSYNC ] diff --git a/src/SQLite3-Core/SQLite3IOErrorLock.class.st b/src/SQLite3-Core/SQLite3IOErrorLock.class.st index 35b8bed..0350084 100644 --- a/src/SQLite3-Core/SQLite3IOErrorLock.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorLock.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorLock class >> nativeErrorCode [ +SQLite3IOErrorLock class >> nativeErrorCode [ ^ SQLITE_IOERR_LOCK ] diff --git a/src/SQLite3-Core/SQLite3IOErrorNoMemory.class.st b/src/SQLite3-Core/SQLite3IOErrorNoMemory.class.st index f5bfb66..8f50bea 100644 --- a/src/SQLite3-Core/SQLite3IOErrorNoMemory.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorNoMemory.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorNoMemory class >> nativeErrorCode [ +SQLite3IOErrorNoMemory class >> nativeErrorCode [ ^ SQLITE_IOERR_NOMEM ] diff --git a/src/SQLite3-Core/SQLite3IOErrorRead.class.st b/src/SQLite3-Core/SQLite3IOErrorRead.class.st index caa710a..dcb6245 100644 --- a/src/SQLite3-Core/SQLite3IOErrorRead.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorRead.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorRead class >> nativeErrorCode [ +SQLite3IOErrorRead class >> nativeErrorCode [ ^ SQLITE_IOERR_READ ] diff --git a/src/SQLite3-Core/SQLite3IOErrorSeek.class.st b/src/SQLite3-Core/SQLite3IOErrorSeek.class.st index e28ce9e..a6bf0b6 100644 --- a/src/SQLite3-Core/SQLite3IOErrorSeek.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorSeek.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorSeek class >> nativeErrorCode [ +SQLite3IOErrorSeek class >> nativeErrorCode [ ^ SQLITE_IOERR_SEEK ] diff --git a/src/SQLite3-Core/SQLite3IOErrorSharedMemoryOpen.class.st b/src/SQLite3-Core/SQLite3IOErrorSharedMemoryOpen.class.st index 5965cad..fe596fa 100644 --- a/src/SQLite3-Core/SQLite3IOErrorSharedMemoryOpen.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorSharedMemoryOpen.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorSharedMemoryOpen class >> nativeErrorCode [ +SQLite3IOErrorSharedMemoryOpen class >> nativeErrorCode [ ^ SQLITE_IOERR_SHMOPEN ] diff --git a/src/SQLite3-Core/SQLite3IOErrorSharedMemorySize.class.st b/src/SQLite3-Core/SQLite3IOErrorSharedMemorySize.class.st index d1781bb..813f0dd 100644 --- a/src/SQLite3-Core/SQLite3IOErrorSharedMemorySize.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorSharedMemorySize.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorSharedMemorySize class >> nativeErrorCode [ +SQLite3IOErrorSharedMemorySize class >> nativeErrorCode [ ^ SQLITE_IOERR_SHMSIZE ] diff --git a/src/SQLite3-Core/SQLite3IOErrorShortRead.class.st b/src/SQLite3-Core/SQLite3IOErrorShortRead.class.st index 4be21d9..4d87725 100644 --- a/src/SQLite3-Core/SQLite3IOErrorShortRead.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorShortRead.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorShortRead class >> nativeErrorCode [ +SQLite3IOErrorShortRead class >> nativeErrorCode [ ^ SQLITE_IOERR_SHORT_READ ] diff --git a/src/SQLite3-Core/SQLite3IOErrorUnlock.class.st b/src/SQLite3-Core/SQLite3IOErrorUnlock.class.st index 0a978e0..0495c5e 100644 --- a/src/SQLite3-Core/SQLite3IOErrorUnlock.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorUnlock.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorUnlock class >> nativeErrorCode [ +SQLite3IOErrorUnlock class >> nativeErrorCode [ ^ SQLITE_IOERR_UNLOCK ] diff --git a/src/SQLite3-Core/SQLite3IOErrorWrite.class.st b/src/SQLite3-Core/SQLite3IOErrorWrite.class.st index d1e01f2..2000533 100644 --- a/src/SQLite3-Core/SQLite3IOErrorWrite.class.st +++ b/src/SQLite3-Core/SQLite3IOErrorWrite.class.st @@ -8,7 +8,7 @@ Class { } { #category : #'private - accessing' } -SQLite3IOErrorWrite class >> nativeErrorCode [ +SQLite3IOErrorWrite class >> nativeErrorCode [ ^ SQLITE_IOERR_WRITE ] diff --git a/src/SQLite3-Core/SQLite3Internal.class.st b/src/SQLite3-Core/SQLite3Internal.class.st index b108ce8..49919f0 100644 --- a/src/SQLite3-Core/SQLite3Internal.class.st +++ b/src/SQLite3-Core/SQLite3Internal.class.st @@ -11,6 +11,6 @@ Class { { #category : #'private - accessing' } SQLite3Internal class >> nativeErrorCode [ - + ^ SQLITE_INTERNAL ] diff --git a/src/SQLite3-Core/SQLite3Library.class.st b/src/SQLite3-Core/SQLite3Library.class.st index 634d972..f64015d 100644 --- a/src/SQLite3-Core/SQLite3Library.class.st +++ b/src/SQLite3-Core/SQLite3Library.class.st @@ -37,14 +37,14 @@ SQLite3Library class >> current [ { #category : #'unified FFI - binding' } SQLite3Library class >> ffiBindingOf: aTypeName [ - + ^ TypeMap at: aTypeName ifAbsent: [ super ffiBindingOf: aTypeName ] ] { #category : #'class initialization' } SQLite3Library class >> initialize [ - self + self initializeTypeMap; initializeDataTypeMap; initializeDateTimeTypeMap @@ -54,7 +54,7 @@ SQLite3Library class >> initialize [ SQLite3Library class >> initializeDataTypeMap [ DataTypeMap := Dictionary newFromPairs: #( - 1 #integerAt: + 1 #integerAt: 2 #floatAt: 3 #stringAt: 4 #byteArrayAt: @@ -64,12 +64,11 @@ SQLite3Library class >> initializeDataTypeMap [ { #category : #'private - accessing' } SQLite3Library class >> initializeDateTimeTypeMap [ - DateTimeTypeMap := { + DateTimeTypeMap := { 'datetime' -> #dateTimeAt:. 'date' -> #dateAt:. - 'timestamp' -> #timestampAt:. + 'timestamp' -> #timestampAt:. 'time' -> #timeAt: } asDictionary - ] { #category : #'private - initialization' } @@ -78,7 +77,7 @@ SQLite3Library class >> initializeTypeMap [ TypeMap := Dictionary newFromPairs: #( sqlite3 #SQLite3DatabaseExternalObject sqlite3_stmt #SQLite3StatementExternalObject - sqlite3_backup #NBSQLite3BackupExternalObject + sqlite3_backup #NBSQLite3BackupExternalObject "sqlite3_blob NBSQLite3BlobExternalObject " sqlite3_int64 FFIInt64 ) @@ -92,31 +91,28 @@ SQLite3Library class >> reset [ { #category : #'private - api' } SQLite3Library >> apiBackupFinish: backupHandle [ "int sqlite3_backup_finish(sqlite3_backup *p)" - - ^ self ffiCall: #(int sqlite3_backup_finish(SQLite3BackupExternalReference *backupHandle)) - + ^ self ffiCall: #(int sqlite3_backup_finish(SQLite3BackupExternalReference *backupHandle)) ] { #category : #'private - api' } SQLite3Library >> apiBackupPageCount: backupHandle [ "int sqlite3_backup_pagecount(sqlite3_backup *p)" - - ^ self ffiCall: #(int sqlite3_backup_pagecount(sqlite3_backup *backupHandle)) + ^ self ffiCall: #(int sqlite3_backup_pagecount(sqlite3_backup *backupHandle)) ] { #category : #'private - api' } SQLite3Library >> apiBackupRemaining: backupHandle [ "int sqlite3_backup_remaining(sqlite3_backup *p)" - + ^ self ffiCall: #(int sqlite3_backup_remaining(sqlite3_backup *backupHandle)) ] { #category : #'private - api' } SQLite3Library >> apiBackupStep:nPage via: backupHandle [ "int sqlite3_backup_step(sqlite3_backup *p, int nPage)" - + ^ self ffiCall: #(int sqlite3_backup_step(SQLite3BackupExternalReference *backupHandle, int nPage)) ] @@ -128,7 +124,7 @@ SQLite3Library >> apiBackupTo: pDest named: zDestName from: pSource named: zSour sqlite3 *pSource, /* Source database handle */ const char *zSourceName /* Source database name */ )" - + ^ self ffiCall: #(SQLite3BackupExternalReference *sqlite3_backup_init( sqlite3 *pDest, String zDestName, sqlite3 *pSource, String zSourceName)) ] @@ -138,16 +134,13 @@ SQLite3Library >> apiBindBlob: aStatement atColumn: aColumn with: aByteArray wit "int sqlite3_bind_blob(sqlite3_stmt*, int, const void *, int, void(*)(void*))" ^ self ffiCall: #(int sqlite3_bind_blob (sqlite3_stmt* aStatement, int aColumn, void* aByteArray, int anInteger, int aPointer)) "SQLITE_TRANSIENT" - ] { #category : #'private - api' } SQLite3Library >> apiBindDouble: aStatement atColumn: aColumn with: aFloat [ "int sqlite3_bind_double(sqlite3_stmt*, int, double)" - - ^ self ffiCall: #(int sqlite3_bind_double (sqlite3_stmt* aStatement, int aColumn, double aFloat)) - + ^ self ffiCall: #(int sqlite3_bind_double (sqlite3_stmt* aStatement, int aColumn, double aFloat)) ] { #category : #'private - api' } @@ -156,7 +149,6 @@ SQLite3Library >> apiBindInteger: aStatement atColumn: aColumn with: anInteger [ ^ self ffiCall: #(int sqlite3_bind_int64 (sqlite3_stmt* aStatement,int aColumn,sqlite3_int64 anInteger)) - ] { #category : #'private - api' } @@ -164,8 +156,6 @@ SQLite3Library >> apiBindNull: aStatement atColumn: aColumn [ "int sqlite3_bind_null(sqlite3_stmt*, int)" ^ self ffiCall: #(int sqlite3_bind_null (sqlite3_stmt* aStatement, int aColumn)) - - ] { #category : #'private - api' } @@ -173,7 +163,6 @@ SQLite3Library >> apiBindParameterCount: aStatement [ "int sqlite3_bind_parameter_count(sqlite3_stmt*)" ^ self ffiCall: #(int sqlite3_bind_parameter_count (sqlite3_stmt* aStatement)) - ] { #category : #'private - api' } @@ -181,16 +170,13 @@ SQLite3Library >> apiBindParameterIndex: aStatement for: aName [ "int sqlite3_bind_parameter_index(sqlite3_stmt*, const char* zName)" ^ self ffiCall: #(int sqlite3_bind_parameter_index (sqlite3_stmt* aStatement, String aName)) - - ] { #category : #'private - api' } SQLite3Library >> apiBindText: aStatement atColumn: aColumn with: aString with: anInteger with: anotherInteger [ "int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int, void(*)(void*))" - + ^ self ffiCall: #(int sqlite3_bind_text (sqlite3_stmt* aStatement, int aColumn, String aString, int anInteger, int anotherInteger)) - ] { #category : #'private - api' } @@ -198,8 +184,6 @@ SQLite3Library >> apiChanges: handle [ "int sqlite3_changes(sqlite3*)" ^ self ffiCall: #(int sqlite3_changes (sqlite3 *handle)) - - ] { #category : #'private - api' } @@ -207,25 +191,20 @@ SQLite3Library >> apiClearBindings: aStatement [ "int sqlite3_clear_bindings(sqlite3_stmt*)" ^ self ffiCall: #(int sqlite3_clear_bindings (sqlite3_stmt* aStatement)) - - ] { #category : #'private - api' } SQLite3Library >> apiClose: handle [ "int sqlite3_close_v2(sqlite3*)" - - ^self ffiCall: #(int sqlite3_close_v2(sqlite3 *handle)) - + + ^self ffiCall: #(int sqlite3_close_v2(sqlite3 *handle)) ] { #category : #'private - api' } SQLite3Library >> apiColumnBlob: aStatement atColumn: aColumn [ "const void *sqlite3_column_blob(sqlite3_stmt*, int)" - - ^ self ffiCall: #(const void *sqlite3_column_blob (sqlite3_stmt* aStatement, int aColumn)) - + ^ self ffiCall: #(const void *sqlite3_column_blob (sqlite3_stmt* aStatement, int aColumn)) ] { #category : #'private - api' } @@ -233,16 +212,13 @@ SQLite3Library >> apiColumnBytes: aStatement atColumn: aColumn [ "int sqlite3_column_bytes(sqlite3_stmt*, int)" ^ self ffiCall: #(int sqlite3_column_bytes (sqlite3_stmt* aStatement, int aColumn)) - - ] { #category : #'private - api' } SQLite3Library >> apiColumnCount: aStatement [ "int sqlite3_column_count(sqlite3_stmt *pStmt)" - - ^ self ffiCall: #(int sqlite3_column_count(sqlite3_stmt *aStatement)) + ^ self ffiCall: #(int sqlite3_column_count(sqlite3_stmt *aStatement)) ] { #category : #'private - api' } @@ -251,7 +227,6 @@ SQLite3Library >> apiColumnDeclaredType: aStatement atColumn: aColumn [ ^ self ffiCall: #(String sqlite3_column_decltype #(sqlite3_stmt *aStatement, int aColumn)) - ] { #category : #'private - api' } @@ -259,16 +234,13 @@ SQLite3Library >> apiColumnDouble: aStatement atColumn: aColumn [ "double sqlite3_column_double(sqlite3_stmt*, int)" ^ self ffiCall: #(double sqlite3_column_double (sqlite3_stmt* aStatement, int aColumn)) - - ] { #category : #'private - api' } SQLite3Library >> apiColumnInt: aStatement atColumn: aColumn [ "int sqlite3_column_int(sqlite3_stmt*, int)" - - ^ self ffiCall: #(sqlite3_int64 sqlite3_column_int64 (sqlite3_stmt* aStatement, int aColumn)) + ^ self ffiCall: #(sqlite3_int64 sqlite3_column_int64 (sqlite3_stmt* aStatement, int aColumn)) ] { #category : #'private - api' } @@ -277,16 +249,13 @@ SQLite3Library >> apiColumnName: aStatement atColumn: aColumn [ ^ self ffiCall: #(String sqlite3_column_name(sqlite3_stmt* aStatement, int aColumn)) - ] { #category : #'private - api' } SQLite3Library >> apiColumnText: aStatement atColumn: aColumn [ "const unsigned char *sqlite3_column_text(sqlite3_stmt*, int)" - - ^ self ffiCall: #(String sqlite3_column_text (sqlite3_stmt* aStatement, int aColumn)) - + ^ self ffiCall: #(String sqlite3_column_text (sqlite3_stmt* aStatement, int aColumn)) ] { #category : #'private - api' } @@ -295,7 +264,6 @@ SQLite3Library >> apiColumnType: aStatement atColumn: aColumn [ ^ self ffiCall: #(int sqlite3_column_type(sqlite3_stmt* aStatement,int aColumn)) - ] { #category : #'private - api' } @@ -303,36 +271,33 @@ SQLite3Library >> apiConfigLoadExtension: dbHandle with: op with: onoff with: re "This is a specific invocation of sqlite3_db_config(sqlite3*, int, ...)." ^self ffiCall: #(int sqlite3_db_config (sqlite3 *dbHandle, int op, int onoff, int *retpointer)) - + "Notes from https://www.sqlite.org/c3ref/c_dbconfig_enable_fkey.html: op == SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION -This option is used to enable or disable the sqlite3_load_extension() interface independently of the load_extension() SQL function. The sqlite3_enable_load_extension() API enables or disables both the C-API sqlite3_load_extension() and the SQL function load_extension(). There should be two additional arguments. When the first argument to this interface is 1, then only the C-API is enabled and the SQL function remains disabled. If the first argument to this interface is 0, then both the C-API and the SQL function are disabled. If the first argument is -1, then no changes are made to state of either the C-API or the SQL function. The second parameter is a pointer to an integer into which is written 0 or 1 to indicate whether sqlite3_load_extension() interface is disabled or enabled following this call. The second parameter may be a NULL pointer, in which case the new setting is not reported back. -" +This option is used to enable or disable the sqlite3_load_extension() interface independently of the load_extension() SQL function. The sqlite3_enable_load_extension() API enables or disables both the C-API sqlite3_load_extension() and the SQL function load_extension(). There should be two additional arguments. When the first argument to this interface is 1, then only the C-API is enabled and the SQL function remains disabled. If the first argument to this interface is 0, then both the C-API and the SQL function are disabled. If the first argument is -1, then no changes are made to state of either the C-API or the SQL function. The second parameter is a pointer to an integer into which is written 0 or 1 to indicate whether sqlite3_load_extension() interface is disabled or enabled following this call. The second parameter may be a NULL pointer, in which case the new setting is not reported back. +" ] { #category : #'private - api' } SQLite3Library >> apiDBHandle: statementHandle [ "sqlite3 *sqlite3_db_handle(sqlite3_stmt*);" - - ^self ffiCall: #(SQLite3DatabaseExternalObject *sqlite3_db_handle(SQLite3StatementExternalObject *statementHandle)) + ^self ffiCall: #(SQLite3DatabaseExternalObject *sqlite3_db_handle(SQLite3StatementExternalObject *statementHandle)) ] { #category : #'private - api' } SQLite3Library >> apiDataCount: handle [ "int sqlite3_data_count(sqlite3_stmt*)" - - ^ self ffiCall: #(int sqlite3_data_count (sqlite3_stmt *handle)) + ^ self ffiCall: #(int sqlite3_data_count (sqlite3_stmt *handle)) ] { #category : #'private - api' } -SQLite3Library >> apiErrorMessage: handle [ +SQLite3Library >> apiErrorMessage: handle [ "const char *sqlite3_errmsg(sqlite3*)" - - ^self ffiCall: #(String sqlite3_errmsg(sqlite3 *handle)) - + + ^self ffiCall: #(String sqlite3_errmsg(sqlite3 *handle)) ] { #category : #'private - api' } @@ -340,24 +305,20 @@ SQLite3Library >> apiExec: dbHandle withSQLText: anSQLText with: callback with: "int sqlite3_exec(sqlite3*, const char*, int (*callback), void*, char **)" ^self ffiCall: #(int sqlite3_exec (sqlite3 *dbHandle, String anSQLText, void *callback, void *callbackData, char **errorMessageBuffer)) - - ] { #category : #'private - api' } SQLite3Library >> apiFinalize: handle [ "int sqlite3_finalize(sqlite3_stmt*)" - - ^self ffiCall: #(int sqlite3_finalize(sqlite3_stmt *handle)) - + + ^self ffiCall: #(int sqlite3_finalize(sqlite3_stmt *handle)) ] { #category : #'private - api' } SQLite3Library >> apiGetAutocommit: handle [ "int sqlite3_get_autocommit(sqlite3*);" - + ^ self ffiCall: #(int sqlite3_get_autocommit (sqlite3 *handle)) - ] { #category : #'private - api' } @@ -370,8 +331,8 @@ SQLite3Library >> apiLastInsertRowid: handle [ { #category : #'private - api' } SQLite3Library >> apiLibVersion [ "const char *sqlite3_libversion(void)" - - ^self ffiCall: #(String sqlite3_libversion(void)) + + ^self ffiCall: #(String sqlite3_libversion(void)) ] { #category : #'private - api' } @@ -380,15 +341,13 @@ SQLite3Library >> apiLoadExtension: dbHandle with: zFile with: zProc with: pzErr ^self ffiCall: #(int sqlite3_load_extension (sqlite3 *dbHandle, String zFile, const char *zProc, char **pzErrMsg)) module: self library - ] { #category : #'private - api' } SQLite3Library >> apiOpen: filename via: handle [ "int sqlite3_open(const char*, sqlite3**)" - - ^self ffiCall: #(int sqlite3_open(String filename, sqlite3 **handle)) - + + ^self ffiCall: #(int sqlite3_open(String filename, sqlite3 **handle)) ] { #category : #'private - api' } @@ -399,9 +358,8 @@ SQLite3Library >> apiOpen: filename withFlags: flags vfs: vfs via: handle [ int flags, /* Flags */ const char *zVfs /* Name of VFS module to use */ )" - - ^self ffiCall: #(int sqlite3_open_v2(String filename, sqlite3 **handle, int flags, String vfs)) - + + ^self ffiCall: #(int sqlite3_open_v2(String filename, sqlite3 **handle, int flags, String vfs)) ] { #category : #'private - api' } @@ -409,59 +367,48 @@ SQLite3Library >> apiPrepare: dbHandle withSQLText: anSQLText with: textSize wit "int sqlite3_prepare_v2(sqlite3*, const char*, int, sqlite3_stmt**, const char **)" ^ self ffiCall: #(int sqlite3_prepare_v2 (sqlite3* dbHandle, String anSQLText, int textSize, sqlite3_stmt** sHandle, const char** tail)) - - ] { #category : #'private - api' } SQLite3Library >> apiReset: handle [ "int sqlite3_reset(sqlite3_stmt*)" - - ^ self ffiCall: #(int sqlite3_reset (sqlite3_stmt *handle)) - + ^ self ffiCall: #(int sqlite3_reset (sqlite3_stmt *handle)) ] { #category : #'private - api' } SQLite3Library >> apiSleep [ "int sqlite3_sleep(int)" - + ^ self ffiCall: #(int sqlite3_sleep(int)) ] { #category : #'private - api' } SQLite3Library >> apiSql: handle [ "const char *sqlite3_sql(sqlite3_stmt*)" - - ^ self ffiCall: #(String sqlite3_sql (sqlite3_stmt* handle)) - + ^ self ffiCall: #(String sqlite3_sql (sqlite3_stmt* handle)) ] { #category : #'private - api' } SQLite3Library >> apiStatementReadOnly: handle [ "int sqlite3_stmt_readonly(sqlite3_stmt *pStmt)" - - ^ self ffiCall: #(int sqlite3_stmt_readonly (SQLite3StatementExternalObject * handle)) - + ^ self ffiCall: #(int sqlite3_stmt_readonly (SQLite3StatementExternalObject * handle)) ] { #category : #'private - api' } SQLite3Library >> apiStep: handle [ "int sqlite3_step(sqlite3_stmt*)" - - ^ self ffiCall: #(int sqlite3_step (sqlite3_stmt* handle)) - + ^ self ffiCall: #(int sqlite3_step (sqlite3_stmt* handle)) ] { #category : #'private - api' } SQLite3Library >> apiThreadsafe [ "int sqlite3_threadsafe(void)" - - ^self ffiCall: #(int sqlite3_threadsafe(void)) - + + ^self ffiCall: #(int sqlite3_threadsafe(void)) ] { #category : #'private - api' } @@ -469,15 +416,12 @@ SQLite3Library >> apiTotalChanges: handle [ "int sqlite3_total_changes(sqlite3*)" ^ self ffiCall: #(int sqlite3_total_changes (sqlite3 *handle)) - - ] { #category : #'private - api' } SQLite3Library >> apiTrace: handle with: callback with: appdata [ - ^ self ffiCall: #(void* sqlite3_trace (sqlite3* handle, FFICallback callback, ExternalAddress appdata)) - + ^ self ffiCall: #(void* sqlite3_trace (sqlite3* handle, FFICallback callback, ExternalAddress appdata)) ] { #category : #operating } @@ -498,91 +442,79 @@ SQLite3Library >> bindParameterCount: aStatementHandle [ { #category : #operating } SQLite3Library >> bindParameterIndex: aStatementHandle for: aName [ ^ self apiBindParameterIndex: aStatementHandle for: aName - - ] { #category : #accessing } SQLite3Library >> blobFrom: aStatement at: aColumn [ | address size array | - + address := self apiColumnBlob: aStatement atColumn: aColumn. size := self apiColumnBytes: aStatement atColumn: aColumn. array := address copyFrom: 1 to: size. - ^array - + ^array ] { #category : #accessing } SQLite3Library >> booleanFrom: aStatement at: aColumn [ | declared selector value | - + declared := self apiColumnDeclaredType: aStatement atColumn: aColumn. - (self class booleanTypes includes: declared asLowercase) ifFalse: [ + (self class booleanTypes includes: declared asLowercase) ifFalse: [ SQLite3AbstractError signal: 'Column is not declared as a boolean.' ]. selector := DataTypeMap at: (self apiColumnType: aStatement atColumn: aColumn). (selector = #nilAt:) ifTrue: [ ^ nil ]. - (selector = #stringAt:) + (selector = #stringAt:) ifTrue: [ value := self apiColumnText: aStatement atColumn: aColumn. - (self class booleanSQLTrueWords includes: value asLowercase) + (self class booleanSQLTrueWords includes: value asLowercase) ifTrue: [ ^ true ] ifFalse: [ (self class booleanSQLFalseWords includes: value asLowercase) ifTrue: [ ^ false ] ifFalse: [ SQLite3AbstractError signal: 'Column value cannot be read as a boolean.' ]]]. - (selector = #integerAt:) + (selector = #integerAt:) ifTrue: [ value := self apiColumnInt: aStatement atColumn: aColumn. (value = 1) ifTrue: [ ^ true ] - ifFalse: [ - (value = 0) + ifFalse: [ + (value = 0) ifTrue: [ ^ false ] - ifFalse: [ SQLite3AbstractError signal: 'Column value cannot be read as a boolean.' ]]] - - + ifFalse: [ SQLite3AbstractError signal: 'Column value cannot be read as a boolean.' ]]] ] { #category : #introspection } -SQLite3Library >> changes: aHandle [ +SQLite3Library >> changes: aHandle [ ^ self apiChanges: aHandle - - ] { #category : #'private - utilities' } SQLite3Library >> checkForOk: anInteger on: aHandle [ - ^ self sqlite3ResultFor: anInteger ifNoneMatch: [ - + ^ self sqlite3ResultFor: anInteger ifNoneMatch: [ + (SQLite3NativeError forNativeErrorCode: anInteger messageText: (self apiErrorMessage: aHandle)) signal ] - ] { #category : #cleaning } SQLite3Library >> clearBindings: sHandle on: dbHandle [ - - ^ self checkForOk: (self apiClearBindings: sHandle) on: dbHandle - + ^ self checkForOk: (self apiClearBindings: sHandle) on: dbHandle ] { #category : #'connection handling' } -SQLite3Library >> close: aHandle [ +SQLite3Library >> close: aHandle [ ^ self apiClose: aHandle ] { #category : #'connection handling' } -SQLite3Library >> columnCount: aStatementHandle [ +SQLite3Library >> columnCount: aStatementHandle [ ^ self apiColumnCount: aStatementHandle ] { #category : #accessing } SQLite3Library >> dataValuesAvailable: aStatementHandle [ ^ self apiDataCount: aStatementHandle - - ] { #category : #'connection handling' } @@ -592,35 +524,32 @@ SQLite3Library >> dbHandle: statementHandle [ { #category : #configuring } SQLite3Library >> disableLoadExtension: aHandle [ - ^ self checkForOk: (self apiConfigLoadExtension: aHandle with: 1005 with: 0 with: ExternalAddress new) + ^ self checkForOk: (self apiConfigLoadExtension: aHandle with: 1005 with: 0 with: ExternalAddress new) on: aHandle - + "Magic number 1005 = SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION. See comment in #apiConfigLoadExtension:with:with:with:." - ] { #category : #configuring } SQLite3Library >> enableLoadExtension: aHandle [ - ^ self checkForOk: (self apiConfigLoadExtension: aHandle with: 1005 with: 1 with: ExternalAddress new) + ^ self checkForOk: (self apiConfigLoadExtension: aHandle with: 1005 with: 1 with: ExternalAddress new) on: aHandle - + "Magic number 1005 = SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION. See comment in #apiConfigLoadExtension:with:with:with:." - ] { #category : #operating } SQLite3Library >> execute: anSQLText on: aDBHandle [ - | null | + | null | null := ExternalAddress new. - ^ self checkForOk: (self apiExec: aDBHandle + ^ self checkForOk: (self apiExec: aDBHandle withSQLText: anSQLText with: null with: null with: null) on: aDBHandle - ] { #category : #operating } @@ -651,9 +580,8 @@ SQLite3Library >> integerFrom: aStatement at: aColumn [ { #category : #testing } SQLite3Library >> isThreadsafe [ "http://sqlite.org/c3ref/threadsafe.html" - - ^ self apiThreadsafe - + + ^ self apiThreadsafe ] { #category : #accessing } @@ -663,21 +591,21 @@ SQLite3Library >> lastInsertRowId: dbHandle [ ] { #category : #'private - accessing' } -SQLite3Library >> library [ +SQLite3Library >> library [ ^self libraryName ] { #category : #accessing } SQLite3Library >> libraryVersion [ "See http://sqlite.org/c3ref/libversion.html" - - ^self apiLibVersion + + ^self apiLibVersion ] { #category : #'private - api' } SQLite3Library >> loadExtension: dbHandle with: aFilename [ - ^ self checkForOk: (self apiLoadExtension: dbHandle + ^ self checkForOk: (self apiLoadExtension: dbHandle with: aFilename with: ExternalAddress new with: ExternalAddress new) @@ -689,7 +617,7 @@ SQLite3Library >> macLibraryName [ | pluginDir | pluginDir := FileSystem /'usr'/'lib'. #('libsqlite3.dylib' 'libsqlite3.0.dylib' 'sqlite3/libtclsqlite3.dylib') - detect: [ :each | (pluginDir / each) exists ] + detect: [ :each | (pluginDir / each) exists ] ifFound: [ :libName | ^ (pluginDir / libName) fullName ]. self error: 'Module not found.' @@ -707,135 +635,121 @@ SQLite3Library >> nameFor: aStatement at: aColumn [ ] { #category : #'connection handling' } -SQLite3Library >> open: aFilename via: aHandle [ +SQLite3Library >> open: aFilename via: aHandle [ ^ self checkForOk: (self apiOpen: aFilename via: aHandle) on: aHandle ] { #category : #accessing } -SQLite3Library >> open: aFilename withFlags: flags vfs: vfs via: aHandle [ +SQLite3Library >> open: aFilename withFlags: flags vfs: vfs via: aHandle [ ^ self checkForOk: (self apiOpen: aFilename withFlags: flags vfs: vfs via: aHandle) on: aHandle ] { #category : #accessing } -SQLite3Library >> open: aFilename withFlags: flags via: aHandle [ +SQLite3Library >> open: aFilename withFlags: flags via: aHandle [ ^ self checkForOk: (self apiOpen: aFilename withFlags: flags vfs: nil via: aHandle) on: aHandle ] { #category : #'private - conversion' } SQLite3Library >> pharoStringToUTF8: aPharoString [ "Converts from Pharo Multibyte Characters to SQLite3 UTF-8 storage format" - + ^ZnUTF8Encoder new encodeString: aPharoString ] { #category : #operating } SQLite3Library >> prepare: aStatementHandle on: aDBHandle with: anSQLText [ | utf8SQL | - + utf8SQL := self pharoStringToUTF8: anSQLText. - ^ self checkForOk: (self apiPrepare: aDBHandle + ^ self checkForOk: (self apiPrepare: aDBHandle withSQLText: utf8SQL with: utf8SQL size with: aStatementHandle with: (ExternalAddress new)) on: aDBHandle - - ] { #category : #cleaning } SQLite3Library >> reset: aStatementHandle [ - - ^ aStatementHandle + + ^ aStatementHandle ifNil: [ 0 ] ifNotNil: [ self apiReset: aStatementHandle ] - - ] { #category : #'private - utilities' } SQLite3Library >> signal: exceptionClass with: value on: handle [ (exceptionClass new) - resultCode: value; + resultCode: value; signal: (self apiErrorMessage: handle) ] { #category : #stepping } -SQLite3Library >> sqlText: aStatementHandle [ +SQLite3Library >> sqlText: aStatementHandle [ ^ self apiSql: aStatementHandle - - ] { #category : #'private - utilities' } SQLite3Library >> sqlite3ResultFor: anInteger ifNoneMatch: aBlock [ - ^[ + ^[ SQLite3Result forNativeResultCode: anInteger ] on: NotFound do: aBlock ] { #category : #stepping } -SQLite3Library >> statementReadOnly:handle [ +SQLite3Library >> statementReadOnly:handle [ "int sqlite3_stmt_readonly(sqlite3_stmt *pStmt)" - - ^((self apiStatementReadOnly:handle) = 0) not - + ^((self apiStatementReadOnly:handle) = 0) not ] { #category : #stepping } -SQLite3Library >> step: aStatementHandle [ +SQLite3Library >> step: aStatementHandle [ ^ self apiStep: aStatementHandle - - ] { #category : #testing } SQLite3Library >> threadsafe [ "This method is deprecated so consider to migrate." - self deprecated: 'Please use #isThreadsafe instead' transformWith: '`@receiver threadsafe' + self deprecated: 'Please use #isThreadsafe instead' transformWith: '`@receiver threadsafe' -> '`@receiver isThreadsafe'. - - ^ self isThreadsafe + + ^ self isThreadsafe ] { #category : #introspection } -SQLite3Library >> totalChanges: aHandle [ +SQLite3Library >> totalChanges: aHandle [ ^ self apiTotalChanges: aHandle - - ] { #category : #tracing } SQLite3Library >> trace: handle with: callback with: appdata [ ^ self apiTrace: handle with: callback with: appdata - ] { #category : #'private - utilities' } SQLite3Library >> typeFor: aStatement at: aColumn [ | selector declared | - + declared := (self apiColumnDeclaredType: aStatement atColumn: aColumn). declared notNil ifTrue: [ "Handle column type of boolean as a special case." (self class booleanTypes includes: declared) ifTrue: [ ^ #booleanAt: ]]. - + selector := DataTypeMap at: (self apiColumnType: aStatement atColumn: aColumn). (selector = #stringAt:) ifTrue: [ - declared notNil ifTrue: [ + declared notNil ifTrue: [ "Handle column type of date/time as a special case." ^DateTimeTypeMap at: declared asLowercase ifAbsent: [ selector ]]]. ^ selector - ] { #category : #'private - accessing' } -SQLite3Library >> unix32LibraryName [ +SQLite3Library >> unix32LibraryName [ (#('/usr/lib/i386-linux-gnu' '/usr/lib32' '/usr/lib'), ((OSEnvironment current at: 'LD_LIBRARY_PATH' ifAbsent: [ '' ]) substrings: ':')) - do: [ :path | + do: [ :path | #('libsqlite3.so.0' 'libsqlite3.so') do: [ :libraryName | | libraryPath | libraryPath := path asFileReference / libraryName. @@ -845,30 +759,29 @@ SQLite3Library >> unix32LibraryName [ ] { #category : #'private - accessing' } -SQLite3Library >> unix32ModuleName [ +SQLite3Library >> unix32ModuleName [ "Remove later - this is just to satisfy old Pharo 6" - + ^self unix32LibraryName ] { #category : #'private - accessing' } -SQLite3Library >> unix64LibraryName [ +SQLite3Library >> unix64LibraryName [ (#('/usr/lib/x86_64-linux-gnu' '/lib/x86_64-linux-gnu' '/usr/lib'), ((OSEnvironment current at: 'LD_LIBRARY_PATH' ifAbsent: [ '' ]) substrings: ':')) - do: [ :path | + do: [ :path | #('libsqlite3.so.0' 'libsqlite3.so') do: [ :libraryName | | libraryPath | libraryPath := path asFileReference / libraryName. libraryPath exists ifTrue: [ ^ libraryPath fullName ]]]. self error: 'Module not found.' - ] { #category : #'private - accessing' } -SQLite3Library >> unix64ModuleName [ +SQLite3Library >> unix64ModuleName [ "Remove later - this is just to satisfy old Pharo 6" - + ^self unix64LibraryName ] @@ -878,9 +791,9 @@ SQLite3Library >> win32LibraryName [ ] { #category : #'private - accessing' } -SQLite3Library >> win32ModuleName [ +SQLite3Library >> win32ModuleName [ "Remove later - this is just to satisfy old Pharo 6" - + ^self win32LibraryName ] @@ -902,7 +815,7 @@ SQLite3Library >> with: aStatement at: aColumn putFloat: aFloat [ { #category : #operating } SQLite3Library >> with: aStatement at: aColumn putInteger: anInteger [ - ^ self apiBindInteger: aStatement atColumn: aColumn with: anInteger + ^ self apiBindInteger: aStatement atColumn: aColumn with: anInteger ] { #category : #operating } @@ -921,7 +834,6 @@ SQLite3Library >> with: aStatement at: aColumn putText: aString [ ] { #category : #operating } -SQLite3Library >> with: aStatement putNullAt: aColumn [ +SQLite3Library >> with: aStatement putNullAt: aColumn [ ^ self apiBindNull: aStatement atColumn: aColumn - ] diff --git a/src/SQLite3-Core/SQLite3Locked.class.st b/src/SQLite3-Core/SQLite3Locked.class.st index 32ad023..0e6bc3b 100644 --- a/src/SQLite3-Core/SQLite3Locked.class.st +++ b/src/SQLite3-Core/SQLite3Locked.class.st @@ -12,7 +12,7 @@ Class { } { #category : #'private - accessing' } -SQLite3Locked class >> nativeErrorCode [ - +SQLite3Locked class >> nativeErrorCode [ + ^ SQLITE_LOCKED ] diff --git a/src/SQLite3-Core/SQLite3Misuse.class.st b/src/SQLite3-Core/SQLite3Misuse.class.st index a4a0d82..ead5001 100644 --- a/src/SQLite3-Core/SQLite3Misuse.class.st +++ b/src/SQLite3-Core/SQLite3Misuse.class.st @@ -12,7 +12,7 @@ Class { } { #category : #'private - accessing' } -SQLite3Misuse class >> nativeErrorCode [ - +SQLite3Misuse class >> nativeErrorCode [ + ^ SQLITE_MISUSE ] diff --git a/src/SQLite3-Core/SQLite3NativeError.class.st b/src/SQLite3-Core/SQLite3NativeError.class.st index 238d310..4f9bdd2 100644 --- a/src/SQLite3-Core/SQLite3NativeError.class.st +++ b/src/SQLite3-Core/SQLite3NativeError.class.st @@ -26,12 +26,10 @@ SQLite3NativeError class >> forNativeErrorCode: anInteger messageText: aString [ ^(self subclassForNativeErrorCode: anInteger) new messageText: aString; yourself - - ] { #category : #testing } -SQLite3NativeError class >> isAbstract [ +SQLite3NativeError class >> isAbstract [ ^self name = #SQLite3NativeError ] @@ -39,12 +37,12 @@ SQLite3NativeError class >> isAbstract [ { #category : #'private - accessing' } SQLite3NativeError class >> nativeErrorCode [ "Returns the native error code as defined by SQLite C library." - + ^ self subclassResponsibility ] { #category : #'private - accessing' } SQLite3NativeError class >> subclassForNativeErrorCode: anInteger [ - ^ self subclasses + ^ self subclasses detect: [ :subclass | subclass nativeErrorCode = anInteger ] ] diff --git a/src/SQLite3-Core/SQLite3PreparedStatement.class.st b/src/SQLite3-Core/SQLite3PreparedStatement.class.st index cc196f7..2d5562f 100644 --- a/src/SQLite3-Core/SQLite3PreparedStatement.class.st +++ b/src/SQLite3-Core/SQLite3PreparedStatement.class.st @@ -20,11 +20,11 @@ Class { { #category : #bindings } SQLite3PreparedStatement >> at: aColumn putBoolean: aBoolean [ - ^ self library - with: handle - at: aColumn + ^ self library + with: handle + at: aColumn putInteger: (aBoolean ifTrue: [ 1 ] ifFalse: [ 0 ]) - + "See http://www.sqlite.org/datatype3.html." ] @@ -41,8 +41,8 @@ SQLite3PreparedStatement >> at: aColumn putDate: aDate [ | string | - string := self bindingAt: aDate ifAbsentPut: [ - String streamContents: [ :stream | + string := self bindingAt: aDate ifAbsentPut: [ + String streamContents: [ :stream | BasicDatePrinter new printDate: aDate format: #( ) on: stream ] ]. ^ self library with: handle at: aColumn putText: string ] @@ -61,7 +61,7 @@ SQLite3PreparedStatement >> at: aColumn putDateTime: aDateTime [ { #category : #bindings } SQLite3PreparedStatement >> at: aColumn putFloat: aFloat [ | f | - + f := (aFloat isKindOf: Fraction) ifTrue: [ aFloat asFloat ] ifFalse: [ aFloat ]. @@ -115,8 +115,8 @@ SQLite3PreparedStatement >> at: aColumn putTime: aTime [ { #category : #public } SQLite3PreparedStatement >> basicExecute: aBlock [ | ret | - - ret := self step. + + ret := self step. (ret = SQLITE_DONE) " == SQLITE_DONE, meaning step should not be sent again." ifTrue: [ aBlock value: self ] ifFalse: [ @@ -147,21 +147,21 @@ SQLite3PreparedStatement >> bindParameters: parameters [ $AAAA A dollar-sign followed by an identifier name also holds a spot for a named parameter with the name $AAAA. The identifier name in this case can include one or more occurrences of '::' and a suffix enclosed in '(...)' containing any text at all. This syntax is the form of a variable name in the Tcl programming language. The presence of this syntax results from the fact that SQLite is really a Tcl extension that has escaped into the wild. Parameters that are not assigned values using sqlite3_bind() are treated as NULL. The sqlite3_bind_parameter_index() interface can be used to translate a symbolic parameter name into its equivalent numeric index." - (parameters isCollection and: [ parameters isString not ]) ifFalse: [ + (parameters isCollection and: [ parameters isString not ]) ifFalse: [ SQLite3AbstractError signal: 'Unable to execute SQL on instance of ' , parameters class asString ]. - parameters keysAndValuesDo: [ :k :v | + parameters keysAndValuesDo: [ :k :v | | idx | k isInteger ifTrue: [ idx := k ] - ifFalse: [ + ifFalse: [ idx := self bindParameterIndex: k. idx = 0 ifTrue: [ idx := self bindParameterIndex: '@' , k ]. idx = 0 ifTrue: [ idx := self bindParameterIndex: ':' , k ]. idx = 0 ifTrue: [ idx := self bindParameterIndex: '$' , k ]. (idx = 0 and: [ k isAllDigits ]) ifTrue: [ idx := k asInteger ] ]. - idx > 0 ifTrue: [ + idx > 0 ifTrue: [ self perform: (self dataTypeForObject: v) with: idx with: v ] ] ] @@ -171,36 +171,34 @@ SQLite3PreparedStatement >> bindingAt: anObject ifAbsentPut: aBlock [ ] { #category : #fetching } -SQLite3PreparedStatement >> booleanAt: aColumn [ +SQLite3PreparedStatement >> booleanAt: aColumn [ ^self library booleanFrom: handle at: aColumn ] { #category : #fetching } SQLite3PreparedStatement >> byteArrayAt: aColumn [ ^ self library blobFrom: handle at: aColumn - ] { #category : #'public - accessing' } -SQLite3PreparedStatement >> changes [ +SQLite3PreparedStatement >> changes [ ^changes ifNil: [ changes := 0 ] ] { #category : #private } SQLite3PreparedStatement >> checkOk: aValue [ - "These are normal conditions." + "These are normal conditions." aValue = SQLITE_OK ifTrue: [ ^aValue ]. - + "These are error conditions." (aValue = SQLITE_BUSY) ifTrue: [ connection signal: SQLite3Busy with: aValue ]. (aValue = SQLITE_MISUSE) - ifTrue: [ connection signal: SQLite3Misuse with: aValue ]. + ifTrue: [ connection signal: SQLite3Misuse with: aValue ]. "Catch any error not specifically handled above." connection signal: SQLite3AbstractError with: aValue - ] { #category : #bindings } @@ -218,12 +216,12 @@ SQLite3PreparedStatement >> columnCount [ ] { #category : #'public - accessing' } -SQLite3PreparedStatement >> columnNames [ - ^columnNames ifNil: [ +SQLite3PreparedStatement >> columnNames [ + ^columnNames ifNil: [ columnNames := Array new: self columnCount. (1 to: columnNames size) do: [ :c | columnNames at: c put: (self nameOfColumn: c - 1) ]. columnNames - ]. + ] ] { #category : #'private - accessing' } @@ -282,7 +280,7 @@ SQLite3PreparedStatement >> dateTimeAt: aColumn [ { #category : #'private - accessing' } SQLite3PreparedStatement >> dbHandle [ - ^(self library dbHandle: handle) + ^(self library dbHandle: handle) ] { #category : #operating } @@ -300,7 +298,7 @@ SQLite3PreparedStatement >> execute: parameters [ { #category : #initialization } SQLite3PreparedStatement >> finalize [ "Finalize the statement as required by the SQLite3 API. As per the API, the user is expected to finalize a statement after use. - + Since executing a new statement without having finalized the previous one might cause SQLITE_BUSY errors, we can't rely on the garbage collector to execute the finalization, or we'll be exposed to non-deterministic behaviour." handle @@ -333,24 +331,22 @@ SQLite3PreparedStatement >> initialize [ ] { #category : #fetching } -SQLite3PreparedStatement >> integerAt: aColumn [ +SQLite3PreparedStatement >> integerAt: aColumn [ ^self library integerFrom: handle at: aColumn ] { #category : #'private - testing' } SQLite3PreparedStatement >> isFloatLike: anObject [ ^ (anObject isKindOf: Float) or: [ anObject isKindOf: Fraction ] - - ] { #category : #'public - accessing' } -SQLite3PreparedStatement >> isReadOnly [ +SQLite3PreparedStatement >> isReadOnly [ ^self library statementReadOnly: handle ] { #category : #'private - accessing' } -SQLite3PreparedStatement >> library [ +SQLite3PreparedStatement >> library [ ^SQLite3Library current ] @@ -361,17 +357,17 @@ SQLite3PreparedStatement >> nameOfColumn: aColumn [ { #category : #fetching } SQLite3PreparedStatement >> nilAt: aColumn [ - ^ nil + ^ nil ] { #category : #fetching } SQLite3PreparedStatement >> objectAt: aColumn [ - ^ FLMaterializer materializeFromByteArray: (self library blobFrom: handle at: aColumn) + ^ FLMaterializer materializeFromByteArray: (self library blobFrom: handle at: aColumn) ] { #category : #public } SQLite3PreparedStatement >> prepare: anSQLText [ - self library prepare: handle on: connection handle with: anSQLText. + self library prepare: handle on: connection handle with: anSQLText ] { #category : #public } @@ -380,7 +376,7 @@ SQLite3PreparedStatement >> reset [ ] { #category : #operating } -SQLite3PreparedStatement >> sqlText [ +SQLite3PreparedStatement >> sqlText [ ^ self library sqlText: handle ] @@ -392,22 +388,21 @@ SQLite3PreparedStatement >> step [ { #category : #private } SQLite3PreparedStatement >> stepOk: aValue [ - "These are normal conditions." + "These are normal conditions." (aValue = SQLITE_ROW or: [aValue = SQLITE_DONE]) ifTrue: [ changes := connection changes. ^aValue ]. - + "These are error conditions." (aValue = SQLITE_BUSY) ifTrue: [ connection signal: SQLite3Busy with: aValue ]. (aValue = SQLITE_MISUSE) ifTrue: [ connection signal: SQLite3Misuse with: aValue ]. (aValue = SQLITE_CONSTRAINT) - ifTrue: [ connection signal: SQLite3ConstraintViolation with: aValue]. + ifTrue: [ connection signal: SQLite3ConstraintViolation with: aValue]. "Catch any error not specifically handled above." connection signal: SQLite3AbstractError with: aValue - ] { #category : #fetching } @@ -439,5 +434,4 @@ SQLite3PreparedStatement >> typeOfColumn: aColumn [ { #category : #fetching } SQLite3PreparedStatement >> valueOfColumn: aColumn [ ^ self perform: (self typeOfColumn: aColumn) with: aColumn - ] diff --git a/src/SQLite3-Core/SQLite3Result.class.st b/src/SQLite3-Core/SQLite3Result.class.st index 0d9bf2f..9578a07 100644 --- a/src/SQLite3-Core/SQLite3Result.class.st +++ b/src/SQLite3-Core/SQLite3Result.class.st @@ -20,7 +20,7 @@ SQLite3Result class >> forNativeResultCode: anInteger [ ] { #category : #testing } -SQLite3Result class >> isAbstract [ +SQLite3Result class >> isAbstract [ ^self name = #SQLite3Result ] @@ -33,6 +33,6 @@ SQLite3Result class >> nativeResultCode [ { #category : #'private - accessing' } SQLite3Result class >> subclassForNativeResultCode: anInteger [ - ^ self subclasses - detect: [ :subclass | subclass nativeResultCode = anInteger ] + ^ self subclasses + detect: [ :subclass | subclass nativeResultCode = anInteger ] ] diff --git a/src/SQLite3-Core/SQLite3Row.class.st b/src/SQLite3-Core/SQLite3Row.class.st index 02d0b4d..bfc682b 100644 --- a/src/SQLite3-Core/SQLite3Row.class.st +++ b/src/SQLite3-Core/SQLite3Row.class.st @@ -14,7 +14,7 @@ Class { { #category : #'instance creation' } SQLite3Row class >> new: anInteger [ - ^(self new) + ^(self new) columnNames:(Array new:anInteger); values: (Array new: anInteger); yourself @@ -27,7 +27,7 @@ SQLite3Row >> asArray [ { #category : #converting } SQLite3Row >> asCombinedDictionary [ - ^self asDictionary addAll: ((self values collectWithIndex:[:v :i | i -> v]) asDictionary); yourself + ^self asDictionary addAll: ((self values collectWithIndex:[:v :i | i -> v]) asDictionary); yourself ] { #category : #converting } @@ -40,20 +40,20 @@ SQLite3Row >> asDictionary [ ] { #category : #accessing } -SQLite3Row >> at: aKey [ +SQLite3Row >> at: aKey [ ^ self at: aKey ifAbsent: [ ] ] { #category : #accessing } SQLite3Row >> at: aKey ifAbsent: aBlock [ - ^ aKey isInteger - ifTrue: [ self values at: aKey ifAbsent: aBlock ] + ^ aKey isInteger + ifTrue: [ self values at: aKey ifAbsent: aBlock ] ifFalse: [ self values at:(self columnNames indexOf: aKey) ifAbsent: aBlock ] ] { #category : #accessing } SQLite3Row >> at: aKey put: anObject [ - ^ aKey isInteger + ^ aKey isInteger ifTrue: [self atIndex: aKey put: anObject] ifFalse: [ self atName: aKey put: anObject ] ] @@ -69,20 +69,20 @@ SQLite3Row >> atIndex: anIndex put: anObject [ ] { #category : #accessing } -SQLite3Row >> atName: aKey [ +SQLite3Row >> atName: aKey [ | idx | idx := self columnNames indexOf: aKey. - ^idx = 0 + ^idx = 0 ifTrue: [ SQLite3Misuse - signal: 'Attept to set invalid column name ', aKey, ' in result set' ] + signal: 'Attept to set invalid column name ', aKey, ' in result set' ] ifFalse: [ values at: idx ] ] { #category : #accessing } SQLite3Row >> atName: aKey put: anObject [ | idx | - ^ (idx := self columnNames indexOf: aKey) isZero - ifTrue: [ + ^ (idx := self columnNames indexOf: aKey) isZero + ifTrue: [ columnNames := self columnNames copyWith: aKey. values := self values copyWith: anObject ] ifFalse: [ values at: idx put: anObject ] @@ -113,23 +113,21 @@ SQLite3Row >> dataCount [ { #category : #'reflective operations' } SQLite3Row >> doesNotUnderstand: aMessage [ - ^ self at: aMessage selector asString - ifAbsent: [ + ^ self at: aMessage selector asString + ifAbsent: [ "20160514: This bit, for Glorp integration, feels a bit iffy." - self at: aMessage selector asString asUppercase + self at: aMessage selector asString asUppercase ifAbsent: [ super doesNotUnderstand: aMessage ]] ] { #category : #accessing } SQLite3Row >> first [ ^ self values ifEmpty: [] ifNotEmpty: [:v | v first ] - ] { #category : #accessing } SQLite3Row >> last [ ^ self values ifEmpty: [ nil ] ifNotEmpty: [:v | v last ] - ] { #category : #accessing } diff --git a/src/SQLite3-Core/SQLite3Table.class.st b/src/SQLite3-Core/SQLite3Table.class.st index 99bb2c8..8271354 100644 --- a/src/SQLite3-Core/SQLite3Table.class.st +++ b/src/SQLite3-Core/SQLite3Table.class.st @@ -12,7 +12,7 @@ Class { } { #category : #'instance creation' } -SQLite3Table class >> properties: aDictionary in: aDatabase [ +SQLite3Table class >> properties: aDictionary in: aDatabase [ ^ self new database: aDatabase; properties: aDictionary; @@ -29,9 +29,8 @@ SQLite3Table >> columnNames [ SQLite3Table >> columns [ ^ self database execute: 'pragma table_info(', self name , ');' - doing: [:result | + doing: [:result | result rows collect: [ :each |SQLite3Column readFromTableInfoResult: each ]] - ] { #category : #accessing } From 7568d8a23fa6c45fab062906cb977e28bcf96271 Mon Sep 17 00:00:00 2001 From: Torsten Bergmann Date: Sun, 17 Sep 2023 22:09:39 +0200 Subject: [PATCH 5/5] Formatting