Skip to content

Commit ae53a57

Browse files
committed
修改数据数据的时候如果数据类型是int,long,float,double的时候,默认保存问text,导致排序错误的问题
1 parent 7721ca8 commit ae53a57

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/net/tsz/afinal/db/sqlite/SqlBuilder.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,27 +310,36 @@ public static String getCreatTableSQL(Class<?> clazz){
310310
strSQL.append(" ( ");
311311

312312
Class<?> primaryClazz = id.getDataType();
313-
if( primaryClazz == int.class || primaryClazz==Integer.class)
314-
strSQL.append("\"").append(id.getColumn()).append("\" ").append("INTEGER PRIMARY KEY AUTOINCREMENT,");
315-
else
316-
strSQL.append("\"").append(id.getColumn()).append("\" ").append("TEXT PRIMARY KEY,");
313+
if( primaryClazz == int.class || primaryClazz==Integer.class
314+
|| primaryClazz == long.class || primaryClazz == Long.class){
315+
strSQL.append(id.getColumn()).append(" INTEGER PRIMARY KEY AUTOINCREMENT,");
316+
}else{
317+
strSQL.append(id.getColumn()).append(" TEXT PRIMARY KEY,");
318+
}
319+
320+
317321

318322
Collection<Property> propertys = table.propertyMap.values();
319323
for(Property property : propertys){
320-
strSQL.append("\"").append(property.getColumn());
321-
if(property.getDataType() == int.class || property.getDataType() == Integer.class
322-
|| property.getDataType() == long.class || property.getDataType() == Long.class){
324+
strSQL.append(property.getColumn());
325+
Class<?> dataType = property.getDataType();
326+
if( dataType== int.class || dataType == Integer.class
327+
|| dataType == long.class || dataType == Long.class){
323328
strSQL.append(" INTEGER");
324-
}else if(property.getDataType() == float.class || property.getDataType() == Float.class
325-
|| property.getDataType() == double.class || property.getDataType() == Double.class){
329+
}else if(dataType == float.class ||dataType == Float.class
330+
||dataType == double.class || dataType == Double.class){
326331
strSQL.append(" REAL");
332+
}else if (dataType == boolean.class || dataType == Boolean.class) {
333+
strSQL.append(" NUMERIC");
327334
}
328-
strSQL.append("\",");
335+
strSQL.append(",");
329336
}
330337

331338
Collection<ManyToOne> manyToOnes = table.manyToOneMap.values();
332339
for(ManyToOne manyToOne : manyToOnes){
333-
strSQL.append("\"").append(manyToOne.getColumn()).append("\",");
340+
strSQL.append(manyToOne.getColumn())
341+
.append(" INTEGER")
342+
.append(",");
334343
}
335344
strSQL.deleteCharAt(strSQL.length() - 1);
336345
strSQL.append(" )");

0 commit comments

Comments
 (0)