@@ -8,16 +8,16 @@ import org.sqlite.Function
88import org.sqlite.SQLiteConfig
99import org.sqlite.SQLiteOpenMode
1010import java.text.Collator
11- import java.util.*
11+ import java.util.Locale
1212
1313fun Open (path : String , openFlags : Int , label : String , enableTrace : Boolean , enableProfile : Boolean ): NativeDB {
1414 NativeDB .load()
1515 val db = NativeDB (null , path, SQLiteConfig ())
16- val flags = (0 .. 31 ).asSequence()
16+ val flags = (0 .. 31 ).asSequence()
1717 .map { 1 shl it }
1818 .filter { it and openFlags > 0 }
1919 .map {
20- when (it) {
20+ when (it) {
2121 SQLiteDatabase .CREATE_IF_NECESSARY -> SQLiteOpenMode .READWRITE .flag or SQLiteOpenMode .CREATE .flag
2222 SQLiteDatabase .OPEN_READONLY -> {
2323 db.config.isExplicitReadOnly = true
@@ -44,16 +44,18 @@ fun RegisterCustomFunction(
4444 args.indices.forEach { args[it] = value_text(it) }
4545// function.callback.callback(args)
4646 }
47-
4847 }
4948 connectionPtr.create_function(function.name, callback, function.numArgs, 0 )
5049}
5150
5251fun RegisterLocalizedCollators (connectionPtr : NativeDB , locale : String ) {
5352 val collator = Collator .getInstance(Locale .forLanguageTag(locale))
54- connectionPtr.create_collation(locale, object : Collation () {
55- override fun xCompare (str1 : String? , str2 : String? ) = collator.compare(str1, str2)
56- })
53+ connectionPtr.create_collation(
54+ locale,
55+ object : Collation () {
56+ override fun xCompare (str1 : String? , str2 : String? ) = collator.compare(str1, str2)
57+ }
58+ )
5759}
5860
5961fun PrepareStatement (connectionPtr : NativeDB , sql : String ) =
@@ -124,49 +126,49 @@ fun ExecuteForLastInsertedRowId(connectionPtr: NativeDB, statementPtr: Long): Lo
124126fun ExecuteForCursorWindow (connectionPtr : NativeDB , statementPtr : Long , win : CursorWindow , startPos : Int , iRowRequired : Int , countAllRows : Boolean ): Long {
125127
126128 /* Set the number of columns in the window */
127- if (! win.setNumColumns(connectionPtr.column_count(statementPtr))) return 0
129+ if (! win.setNumColumns(connectionPtr.column_count(statementPtr))) return 0
128130
129- var nRow = 0 ;
130- var iStart = startPos;
131- var bOk = true ;
131+ var nRow = 0
132+ var iStart = startPos
133+ var bOk = true
132134
133- while (connectionPtr.step(statementPtr) == Codes .SQLITE_ROW ) {
135+ while (connectionPtr.step(statementPtr) == Codes .SQLITE_ROW ) {
134136 /* Only copy in rows that occur at or after row index iStart. */
135- if ((nRow >= iStart) && bOk){
136- bOk = copyRowToWindow(connectionPtr, win, (nRow - iStart), statementPtr);
137- if (! bOk){
137+ if ((nRow >= iStart) && bOk) {
138+ bOk = copyRowToWindow(connectionPtr, win, (nRow - iStart), statementPtr)
139+ if (! bOk) {
138140 /* The CursorWindow object ran out of memory. If row iRowRequired was
139141 ** not successfully added before this happened, clear the CursorWindow
140142 ** and try to add the current row again. */
141- if ( nRow<= iRowRequired ) {
142- bOk = win.setNumColumns(connectionPtr.column_count(statementPtr));
143- if (! bOk){
144- connectionPtr.reset(statementPtr);
145- return 0 ;
143+ if ( nRow <= iRowRequired) {
144+ bOk = win.setNumColumns(connectionPtr.column_count(statementPtr))
145+ if (! bOk) {
146+ connectionPtr.reset(statementPtr)
147+ return 0
146148 }
147- iStart = nRow;
148- bOk = copyRowToWindow(connectionPtr, win, (nRow - iStart), statementPtr);
149+ iStart = nRow
150+ bOk = copyRowToWindow(connectionPtr, win, (nRow - iStart), statementPtr)
149151 }
150152
151153 /* If the CursorWindow is still full and the countAllRows flag is not
152154 ** set, break out of the loop here. If countAllRows is set, continue
153155 ** so as to set variable nRow correctly. */
154- if ( ! bOk && ! countAllRows ) break ;
156+ if ( ! bOk && ! countAllRows) break
155157 }
156158 }
157159
158- nRow++ ;
160+ nRow++
159161 }
160162
161163 /* Finalize the statement. If this indicates an error occurred, throw an
162164 ** SQLiteException exception. */
163- val rc = connectionPtr.reset(statementPtr);
164- if ( rc != Codes .SQLITE_OK ) {
165+ val rc = connectionPtr.reset(statementPtr)
166+ if (rc != Codes .SQLITE_OK ) {
165167 NativeDB .throwex(rc, connectionPtr.errmsg())
166- return 0 ;
168+ return 0
167169 }
168170
169- return iStart.toLong() shl 32 or nRow.toLong();
171+ return iStart.toLong() shl 32 or nRow.toLong()
170172}
171173
172174/*
@@ -176,13 +178,13 @@ fun ExecuteForCursorWindow(connectionPtr: NativeDB, statementPtr: Long, win: Cur
176178** occurs.
177179*/
178180fun copyRowToWindow (connectionPtr : NativeDB , win : CursorWindow , iRow : Int , statementPtr : Long ): Boolean {
179- val nCol = connectionPtr.column_count(statementPtr);
181+ val nCol = connectionPtr.column_count(statementPtr)
180182 val i = 0
181183 var bOk = false
182184
183185 bOk = win.allocRow()
184- for (i in 0 until nCol){
185- when (val type = connectionPtr.column_type(statementPtr, i)) {
186+ for (i in 0 until nCol) {
187+ when (val type = connectionPtr.column_type(statementPtr, i)) {
186188 Codes .SQLITE_NULL -> win.putNull(iRow, i)
187189 Codes .SQLITE_INTEGER -> win.putLong(connectionPtr.column_long(statementPtr, i), iRow, i)
188190 Codes .SQLITE_FLOAT -> win.putDouble(connectionPtr.column_double(statementPtr, i), iRow, i)
@@ -191,8 +193,8 @@ fun copyRowToWindow(connectionPtr: NativeDB, win: CursorWindow, iRow: Int, state
191193 else -> TODO (" Unknown column type: $type " )
192194 }
193195
194- if (! bOk) win.freeLastRow()
196+ if (! bOk) win.freeLastRow()
195197 }
196198
197- return bOk;
199+ return bOk
198200}
0 commit comments