Skip to content

Commit bcf8323

Browse files
committed
Fix a few bugs
1 parent 9d82177 commit bcf8323

File tree

5 files changed

+22
-42
lines changed

5 files changed

+22
-42
lines changed

sqllin-dsl/src/commonMain/kotlin/com/ctrip/sqllin/dsl/annotation/DBRow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package com.ctrip.sqllin.dsl.annotation
1818

1919
/**
2020
* Annotation for where property
21-
* @author yaqiao
21+
* @author Yuang Qiao
2222
*/
2323

2424
@Target(AnnotationTarget.CLASS)

sqllin-dsl/src/commonMain/kotlin/com/ctrip/sqllin/dsl/annotation/DslMaker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package com.ctrip.sqllin.dsl.annotation
1818

1919
/**
2020
* Dsl maker annotations
21-
* @author yaqiao
21+
* @author Yuang Qiao
2222
*/
2323

2424
@DslMarker

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

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,29 @@ internal fun <T> encodeEntities2InsertValues(
3333
) = with(builder) {
3434
val isInsertId = table.primaryKeyInfo?.run {
3535
!isRowId || isInsertWithId
36-
} ?: false
36+
} ?: true
3737
val serializer = table.kSerializer()
3838
append('(')
3939
val primaryKeyIndex = appendDBColumnName(serializer.descriptor, table.primaryKeyInfo?.primaryKeyName, isInsertId)
40+
if (primaryKeyIndex >= 0)
41+
parameters.removeAt(primaryKeyIndex)
4042
append(')')
4143
append(" values ")
4244
val iterator = values.iterator()
43-
if (isInsertId) {
44-
fun appendNext() {
45-
val value = iterator.next()
46-
val encoder = InsertValuesEncoder(parameters)
47-
encoder.encodeSerializableValue(serializer, value)
48-
append(encoder.valuesSQL)
49-
}
50-
if (iterator.hasNext()) {
51-
appendNext()
52-
} else {
53-
return@with
54-
}
55-
while (iterator.hasNext()) {
56-
append(',')
57-
appendNext()
58-
}
45+
fun appendNext() {
46+
val value = iterator.next()
47+
val encoder = InsertValuesEncoder(parameters)
48+
encoder.encodeSerializableValue(serializer, value)
49+
append(encoder.valuesSQL)
50+
}
51+
if (iterator.hasNext()) {
52+
appendNext()
5953
} else {
60-
var index = 0
61-
fun appendNextWithoutPrimaryKey() {
62-
val value = iterator.next()
63-
if (index != primaryKeyIndex) {
64-
val encoder = InsertValuesEncoder(parameters)
65-
encoder.encodeSerializableValue(serializer, value)
66-
append(encoder.valuesSQL)
67-
}
68-
}
69-
if (iterator.hasNext()) {
70-
appendNextWithoutPrimaryKey()
71-
index++
72-
} else {
73-
return@with
74-
}
75-
while (iterator.hasNext()) {
76-
append(',')
77-
appendNextWithoutPrimaryKey()
78-
index++
79-
}
54+
return@with
55+
}
56+
while (iterator.hasNext()) {
57+
append(',')
58+
appendNext()
8059
}
8160
}
8261

@@ -88,7 +67,7 @@ internal fun StringBuilder.appendDBColumnName(
8867
appendDBColumnName(descriptor)
8968
-1
9069
} else {
91-
var index = 0
70+
var index = -1
9271
if (descriptor.elementsCount > 0) {
9372
val elementName = descriptor.getElementName(0)
9473
if (elementName != primaryKeyName)
@@ -98,7 +77,7 @@ internal fun StringBuilder.appendDBColumnName(
9877
}
9978
for (i in 1 ..< descriptor.elementsCount) {
10079
append(',')
101-
val elementName = descriptor.getElementName(9)
80+
val elementName = descriptor.getElementName(i)
10281
if (elementName != primaryKeyName)
10382
append(elementName)
10483
else

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal object Create : Operation {
5353
startsWith(FullNameCache.DOUBLE) -> " DOUBLE"
5454
startsWith(FullNameCache.BOOLEAN) -> " BOOLEAN"
5555
startsWith(FullNameCache.CHAR) -> " CHAR(1)"
56-
startsWith(FullNameCache.STRING) -> " STRING"
56+
startsWith(FullNameCache.STRING) -> " TEXT"
5757
startsWith(FullNameCache.BYTE_ARRAY) -> " BLOB"
5858
else -> throw IllegalStateException("Hasn't support the type '$this' yet")
5959
}

sqllin-processor/src/main/kotlin/com/ctrip/sqllin/processor/ClauseProcessor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class ClauseProcessor(
149149
// Write the override instance for property `primaryKeyInfo`.
150150
if (primaryKeyName == null && compositePrimaryKeys.isEmpty()) {
151151
writer.write(" override val primaryKeyInfo = null\n\n")
152+
writer.write("}\n")
152153
return@use
153154
}
154155
writer.write(" override val primaryKeyInfo = PrimaryKeyInfo(\n")

0 commit comments

Comments
 (0)