Skip to content

Commit 17c2737

Browse files
committed
Substitute joinTos with manual loops.
1 parent 14f23df commit 17c2737

File tree

6 files changed

+28
-18
lines changed

6 files changed

+28
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* New experimental API: `DatabaseScope#CREATE`
1616
* New experimental API: `DatabaseScope#DROP`
1717
* New experimental API: `DatabaseSceop#ALERT`
18+
* Support using ByteArray in DSL, that represents BLOB in SQLite
1819

1920
### sqllin-driver
2021

ROADMAP.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
* Support the key word REFERENCE
66
* Support JOIN sub-query
7-
* Fix the bug of storing ByteArray in DSL
7+
* Support Enum type
8+
* Support typealias for primitive types
89

910
## Medium Priority
1011

sqllin-driver/src/androidMain/kotlin/com/ctrip/sqllin/driver/AndroidDatabaseConnection.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ internal class AndroidDatabaseConnection(private val database: SQLiteDatabase) :
3737

3838
override fun executeUpdateDelete(sql: String, bindParams: Array<out Any?>?) = execSQL(sql, bindParams)
3939

40-
override fun query(sql: String, bindParams: Array<out Any?>?): CommonCursor =
41-
if (bindParams == null) {
42-
AndroidCursor(database.rawQuery(sql, null))
40+
override fun query(sql: String, bindParams: Array<out Any?>?): CommonCursor {
41+
val cursor = if (bindParams == null) {
42+
database.rawQuery(sql, null)
4343
} else {
4444
// Use rawQueryWithFactory to bind parameters with proper types
4545
// This allows us to bind parameters with their actual types (Int, Long, Double, etc.)
@@ -50,8 +50,10 @@ internal class AndroidDatabaseConnection(private val database: SQLiteDatabase) :
5050
}
5151
// Pass emptyArray() for selectionArgs since we bind parameters via the factory
5252
// Use empty string for editTable since it's only needed for updateable cursors
53-
AndroidCursor(database.rawQueryWithFactory(cursorFactory, sql, null, ""))
53+
database.rawQueryWithFactory(cursorFactory, sql, null, "")
5454
}
55+
return AndroidCursor(cursor)
56+
}
5557

5658
/**
5759
* Binds parameters to SQLiteQuery with proper type handling.

sqllin-dsl/src/commonMain/kotlin/com/ctrip/sqllin/dsl/sql/compiler/InsertValuesEncoder.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import kotlinx.serialization.modules.SerializersModule
3737
*
3838
* @param parameters Mutable list to accumulate parameter values
3939
* @param primaryKeyName Name of primary key field to skip, or null to include all fields
40+
* @param isInsertId whether ignore encoding the special primary key that represents rowid in SQLite
4041
*
4142
* @author Yuang Qiao
4243
*/

sqllin-dsl/src/commonMain/kotlin/com/ctrip/sqllin/dsl/sql/operation/Create.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,17 @@ internal object Create : Operation {
114114
append(',')
115115
}
116116
}
117-
table.primaryKeyInfo?.compositePrimaryKeys?.joinTo(
118-
buffer = this,
119-
separator = ",",
120-
prefix = ", PRIMARY KEY (",
121-
postfix = ")",
122-
)
117+
table.primaryKeyInfo?.compositePrimaryKeys?.let {
118+
append(", PRIMARY KEY (")
119+
if (it.isEmpty())
120+
return@let
121+
append(it[0])
122+
for (i in 1 ..< it.size) {
123+
append(',')
124+
append(it[i])
125+
}
126+
append(')')
127+
}
123128
append(')')
124129
}
125130
}

sqllin-dsl/src/commonMain/kotlin/com/ctrip/sqllin/dsl/sql/statement/JoinStatementWithoutCondition.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public class JoinStatementWithoutCondition<R> internal constructor(
5757
require(iterator.hasNext()) { "Param 'clauseElements' must not be empty!!!" }
5858
val sql = buildString {
5959
append(sqlStr)
60-
clauseElements.joinTo(
61-
buffer = this,
62-
separator = ",",
63-
prefix = " USING (",
64-
postfix = ")",
65-
transform = { it.valueName }
66-
)
60+
append(" USING (")
61+
append(iterator.next().valueName)
62+
while (iterator.hasNext()) {
63+
append(',')
64+
append(iterator.next().valueName)
65+
}
66+
append(')')
6767
}
6868
val joinStatement = JoinSelectStatement(sql, deserializer, connection, container, null)
6969
addSelectStatement(joinStatement)

0 commit comments

Comments
 (0)