@@ -620,10 +620,6 @@ - (BOOL)_createTableWithModelClass:(Class)modelClass tableName:(NSString*)tableN
620
620
621
621
NSString * columnType = property.sqlColumnType ;
622
622
623
- if ([columnType isEqualToString: LKSQL_Type_Double]) {
624
- columnType = LKSQL_Type_Text;
625
- }
626
-
627
623
[table_pars appendFormat: @" %@ %@ " , property.sqlColumnName, columnType];
628
624
629
625
if ([property.sqlColumnType isEqualToString: LKSQL_Type_Text]) {
@@ -937,29 +933,36 @@ - (NSMutableArray*)searchBase:(Class)modelClass columns:(id)columns where:(id)wh
937
933
return [self searchBaseWithParams: params];
938
934
}
939
935
936
+ - (NSString *)replaceTableNameIfNeeded : (NSString *)sql withModelClass : (Class )modelClass
937
+ {
938
+ // replace @t to model table name
939
+ NSString * replaceString = [[modelClass getTableName ] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet ]];
940
+ if ([sql hasSuffix: @" @t" ]) {
941
+ sql = [sql stringByAppendingString: @" " ];
942
+ }
943
+ if ([sql componentsSeparatedByString: @" from " ].count == 2 && [sql rangeOfString: @" join " ].length == 0 ) {
944
+ sql = [sql stringByReplacingOccurrencesOfString: @" from " withString: [NSString stringWithFormat: @" ,%@ .rowid from " , replaceString]];
945
+ }
946
+
947
+ sql = [sql stringByReplacingOccurrencesOfString: @" @t "
948
+ withString:
949
+ [NSString stringWithFormat: @" %@ " , replaceString]];
950
+ sql = [sql stringByReplacingOccurrencesOfString: @" @t,"
951
+ withString:
952
+ [NSString stringWithFormat: @" %@ ," , replaceString]];
953
+ sql = [sql stringByReplacingOccurrencesOfString: @" ,@t "
954
+ withString:
955
+ [NSString stringWithFormat: @" ,%@ " , replaceString]];
956
+
957
+ return sql;
958
+ }
959
+
940
960
- (NSMutableArray *)searchWithSQL : (NSString *)sql toClass : (Class )modelClass
941
961
{
942
- // replace @t to model table name
943
- NSString * replaceString = [[modelClass getTableName ] stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet ]];
944
- if ([sql hasSuffix: @" @t" ]) {
945
- sql = [sql stringByAppendingString: @" " ];
946
- }
947
- if ([sql componentsSeparatedByString: @" from " ].count == 2 && [sql rangeOfString: @" join " ].length == 0 ) {
948
- sql = [sql stringByReplacingOccurrencesOfString: @" from " withString: [NSString stringWithFormat: @" ,%@ .rowid from " , replaceString]];
949
- }
950
-
951
- sql = [sql stringByReplacingOccurrencesOfString: @" @t "
952
- withString:
953
- [NSString stringWithFormat: @" %@ " , replaceString]];
954
- sql = [sql stringByReplacingOccurrencesOfString: @" @t,"
955
- withString:
956
- [NSString stringWithFormat: @" %@ ," , replaceString]];
957
- sql = [sql stringByReplacingOccurrencesOfString: @" ,@t "
958
- withString:
959
- [NSString stringWithFormat: @" ,%@ " , replaceString]];
960
-
962
+ sql = [self replaceTableNameIfNeeded: sql withModelClass: modelClass];
961
963
return [self searchWithRAWSQL: sql toClass: modelClass];
962
964
}
965
+
963
966
- (NSMutableArray *)searchWithRAWSQL : (NSString *)sql toClass : (Class )modelClass
964
967
{
965
968
__block NSMutableArray * results = nil ;
@@ -971,6 +974,25 @@ - (NSMutableArray*)searchWithRAWSQL:(NSString*)sql toClass:(Class)modelClass
971
974
return results;
972
975
}
973
976
977
+ - (NSMutableArray *)search : (Class )modelClass withSQL : (NSString *)sql , ...
978
+ {
979
+ va_list args;
980
+ va_start (args, sql);
981
+
982
+ sql = [self replaceTableNameIfNeeded: sql withModelClass: modelClass];
983
+
984
+ va_list *argsPoint = &args;
985
+ __block NSMutableArray *results = nil ;
986
+ [self executeDB: ^(FMDatabase *db) {
987
+ FMResultSet *set = [db executeQuery: sql withVAList: *argsPoint];
988
+ results = [self executeResult: set Class: modelClass tableName: nil ];
989
+ [set close ];
990
+ }];
991
+
992
+ va_end (args);
993
+ return results;
994
+ }
995
+
974
996
- (void )sqlString : (NSMutableString *)sql groupBy : (NSString *)groupBy orderBy : (NSString *)orderby offset : (NSInteger )offset count : (NSInteger )count
975
997
{
976
998
if ([LKDBUtils checkStringIsEmpty: groupBy] == NO ) {
@@ -1549,4 +1571,4 @@ + (LKDBHelper*)getUsingLKDBHelper
1549
1571
1550
1572
@implementation LKDBWeakObject
1551
1573
1552
- @end
1574
+ @end
0 commit comments