-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataObject.incl
661 lines (536 loc) · 26.5 KB
/
DataObject.incl
1
globals "DataObject.glbl"globals "DataObject_Super.incl"include "NSLog.incl"local modedim as CFMutableArrayRef selectcolsArrayRef, selecttablesArrayRef, selectassociationsArrayRef, selectfilterArrayRefdim as CFMutableDictionaryRef columnDictionaryRef, tableDictionaryRef, associationsDictionaryRef, filterDictionaryRefdim as CFMutableStringRef mySQLStringdim as CFIndex sqlColumnCount, sqlTableCount, sqlAssociationCount, sqlFilterCount, idim as CFNumberRef myOperator, columnLogicdim as long aOperator, aLogiclocal fn GenerateSelectSQL( queryDictionaryRef as CFMutableDictionaryRef ) as CFMutableStringRef'~'1mySQLString = fn CFStringCreateMutable( _kCFAllocatorDefault, _noNaxCharacters )fn CFStringAppend(mySQLString, @"SELECT ")if ( fn CFDictionaryContainsKey( queryDictionaryRef, @"selectcols" ) )selectcolsArrayRef = (CFMutableArrayRef)fn CFDictionaryGetValue( queryDictionaryRef, @"selectcols" )if ( selectcolsArrayRef )sqlColumnCount = fn CFArrayGetCount( selectcolsArrayRef )for i = 0 to sqlColumnCount - 1columnDictionaryRef = (CFMutableDictionaryRef) fn CFArrayGetValueAtIndex( selectcolsArrayRef, i )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( columnDictionaryRef, @"columnname" ))fn CFStringAppend( mySQLString, @" AS " )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( columnDictionaryRef, @"aliasname" ))if ( i < sqlColumnCount - 1 ) then fn CFStringAppend( mySQLString, @", ")next iend ifend iffn CFStringAppend( mySQLString, @" FROM " )if ( fn CFDictionaryContainsKey( queryDictionaryRef, @"selecttables" ))selecttablesArrayRef = (CFMutableArrayRef)fn CFDictionaryGetValue( queryDictionaryRef, @"selecttables" )if ( selecttablesArrayRef )sqlTableCount = fn CFArrayGetCount( selecttablesArrayRef )for i = 0 to sqlTableCount - 1tableDictionaryRef = (CFMutableDictionaryRef) fn CFArrayGetValueAtIndex( selecttablesArrayRef, i )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( tableDictionaryRef, @"tablename"))fn CFStringAppend( mySQLString, @" AS ")fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( tableDictionaryRef, @"aliasname"))if ( i < sqlTableCount - 1 ) then fn CFStringAppend( mySQLString, @", ")next iend ifend ifif ( fn CFDictionaryContainsKey( queryDictionaryRef, @"associations" ) )selectassociationsArrayRef = (CFMutableArrayRef)fn CFDictionaryGetValue( queryDictionaryRef, @"associations" )if ( selectassociationsArrayRef )sqlAssociationCount = fn CFArrayGetCount( selectassociationsArrayRef )if ( sqlAssociationCount > 0 )fn CFStringAppend(mySQLString, @" WHERE ")for i = 0 to sqlAssociationCount - 1associationsDictionaryRef = (CFMutableDictionaryRef) fn CFArrayGetValueAtIndex( selectassociationsArrayRef, i )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( associationsDictionaryRef, @"lefttablealias" ))fn CFStringAppend( mySQLString, @"." )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( associationsDictionaryRef, @"leftcolumnname" ))/* * * Operator Meaning * a = b a is equal to b * a != b a is not equal to b * a < b a is less than b * a > b a is greater than b * a <= b a is less than or equal to b * a >= b a is greater than or equal to b * a IN (b, c) a is equal to either b or c * a NOT IN (b, c) a is equal to neither b nor c * a LIKE a is LIKE 'b%' * a NOT LIKE a is NOT LIKE 'b%' * * only equal ( = ) should be used with associations * associations are the JOINS in the SQL SELECT STATEMENT * */myOperator = (CFNumberRef)fn CFDictionaryGetValue( associationsDictionaryRef, @"operator" )fn CFNumberGetValue( myOperator, fn CFNumberGetType( myOperator ), @aOperator )select case aOperatorcase _isEqual : fn CFStringAppend( mySQLString, @" = " )case _isNotEqual : fn CFStringAppend( mySQLString, @" != " )case _isLessThan : fn CFStringAppend( mySQLString, @" < " )case _isGreaterThan : fn CFStringAppend( mySQLString, @" > " )case _isLessThanOrEqual : fn CFStringAppend( mySQLString, @" <= " )case _isGreaterThanOrEqual : fn CFStringAppend( mySQLString, @" >= " )case _isIn : fn CFStringAppend( mySQLString, @" IN " )case _isNotIn : fn CFStringAppend( mySQLString, @" NOT IN " )end selectfn CFRelease( myOperator )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( associationsDictionaryRef, @"righttablealias" ))fn CFStringAppend( mySQLString, @".")fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( associationsDictionaryRef, @"rightcolumnname" ))if i > 0 and i <= sqlTableCount - 1 then fn CFStringAppend( mySQLString, @" AND " )next iend ifend ifend ifif ( fn CFDictionaryContainsKey( queryDictionaryRef, @"filter" ) )selectfilterArrayRef = (CFMutableArrayRef)fn CFDictionaryGetValue( queryDictionaryRef, @"filter" )if ( selectfilterArrayRef )sqlFilterCount = fn CFArrayGetCount( selectfilterArrayRef )if ( sqlFilterCount > 0 )if sqlFilterCount > 0 and sqlAssociationCount > 0 then fn CFStringAppend( mySQLString, @" AND " )if sqlFilterCount > 0 and sqlAssociationCount = 0 then fn CFStringAppend( mySQLString, @" WHERE " )for i = 0 to sqlFilterCount - 1/* * * Logic Meaning * _and AND * _or OR * */filterDictionaryRef = (CFMutableDictionaryRef) fn CFArrayGetValueAtIndex( selectfilterArrayRef, i )if ( fn CFDictionaryContainsKey( filterDictionaryRef, @"logic" ))columnLogic = (CFNumberRef)fn CFDictionaryGetValue( filterDictionaryRef, @"logic" )fn CFNumberGetValue( columnLogic, fn CFNumberGetType( columnLogic), @aLogic )select case aLogiccase _andif i > 0 and i <= sqlFilterCount - 1 then fn CFStringAppend( mySQLString, @" AND " )case _orif i > 0 and i <= sqlFilterCount - 1 then fn CFStringAppend( mySQLString, @" OR " )end selectfn CFRelease( columnLogic )end iffn CFStringAppend( mySQLString, fn CFDictionaryGetValue( filterDictionaryRef, @"tablealias" ))fn CFStringAppend( mySQLString, @"." )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( filterDictionaryRef, @"columnname" ))/* * * Operator Meaning * a = b a is equal to b * a != b a is not equal to b * a < b a is less than b * a > b a is greater than b * a <= b a is less than or equal to b * a >= b a is greater than or equal to b * a IN (b, c) a is equal to either b or c * a NOT IN (b, c) a is equal to neither b nor c * * only equal ( = ) should be used with associations * associations are the JOINS in the SQL SELECT STATEMENT * */myOperator = (CFNumberRef)fn CFDictionaryGetValue( filterDictionaryRef, @"operator" )fn CFNumberGetValue( myOperator, fn CFNumberGetType( myOperator ), @aOperator )select case aOperatorcase _isEqual : fn CFStringAppend( mySQLString, @" = " ) : fn CFStringAppend( mySQLString, @" ? " )case _isNotEqual : fn CFStringAppend( mySQLString, @" != " ) : fn CFStringAppend( mySQLString, @" ? " )case _isLessThan : fn CFStringAppend( mySQLString, @" < " ) : fn CFStringAppend( mySQLString, @" ? " )case _isGreaterThan : fn CFStringAppend( mySQLString, @" > " ) : fn CFStringAppend( mySQLString, @" ? " )case _isLessThanOrEqual : fn CFStringAppend( mySQLString, @" <= " ) : fn CFStringAppend( mySQLString, @" ? " )case _isGreaterThanOrEqual : fn CFStringAppend( mySQLString, @" >= " ) : fn CFStringAppend( mySQLString, @" ? " )case _isIn : fn CFStringAppend( mySQLString, @" IN " ) : fn CFStringAppend( mySQLString, @" ? " )case _isNotIn : fn CFStringAppend( mySQLString, @" NOT IN " ) : fn CFStringAppend( mySQLString, @" ? " )case _isNull : fn CFStringAppend( mySQLString, @" ISNULL " )case _isNotNull : fn CFStringAppend( mySQLString, @" NOTNULL " )case _isLike : fn CFStringAppend( mySQLString, @" LIKE " ) : fn CFStringAppend( mySQLString, @" ? " )case _isNotLike : fn CFStringAppend( mySQLString, @" NOT LIKE " ) : fn CFStringAppend( mySQLString, @" ? " )end selectfn CFRelease( myOperator )next iend ifend ifend ifend fn = mySQLStringlocal modedim as CFMutableArrayRef selectcolsArrayRef, selecttablesArrayRef, selectassociationsArrayRef, selectfilterArrayRefdim as CFMutableDictionaryRef columnDictionaryRef, tableDictionaryRef, associationsDictionaryRef, filterDictionaryRefdim as CFMutableStringRef mySQLStringdim as CFIndex sqlColumnCount, sqlTableCount, sqlAssociationCount, sqlFilterCount, idim as CFNumberRef myOperator, columnLogicdim as long aOperator, aLogiclocal fn GenerateUpdateSQL( queryDictionaryRef as CFMutableDictionaryRef ) as CFMutableStringRef'~'1mySQLString = fn CFStringCreateMutable( _kCFAllocatorDefault, _noNaxCharacters )fn CFStringAppend(mySQLString, @"SELECT ")if ( fn CFDictionaryContainsKey( queryDictionaryRef, @"selectcols" ))selectcolsArrayRef = (CFMutableArrayRef)fn CFDictionaryGetValue( queryDictionaryRef, @"selectcols" )if ( selectcolsArrayRef )sqlColumnCount = fn CFArrayGetCount( selectcolsArrayRef )for i = 0 to sqlColumnCount - 1columnDictionaryRef = (CFMutableDictionaryRef) fn CFArrayGetValueAtIndex( selectcolsArrayRef, i )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( columnDictionaryRef, @"columnname" ))fn CFStringAppend( mySQLString, @" AS " )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( columnDictionaryRef, @"aliasname" ))if ( i < sqlColumnCount - 1 ) then fn CFStringAppend( mySQLString, @", " )next iend ifend iffn CFStringAppend( mySQLString, @" FROM " )if ( fn CFDictionaryContainsKey( queryDictionaryRef, @"selecttables" ))selecttablesArrayRef = (CFMutableArrayRef)fn CFDictionaryGetValue( queryDictionaryRef, @"selecttables" )if ( selecttablesArrayRef )sqlTableCount = fn CFArrayGetCount( selecttablesArrayRef )for i = 0 to sqlTableCount - 1tableDictionaryRef = (CFMutableDictionaryRef) fn CFArrayGetValueAtIndex( selecttablesArrayRef, i )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue(tableDictionaryRef, @"tablename" ))fn CFStringAppend( mySQLString, @" AS " )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue(tableDictionaryRef, @"aliasname" ))if ( i < sqlTableCount - 1 ) then fn CFStringAppend(mySQLString, @", " )next iend ifend ifif ( fn CFDictionaryContainsKey( queryDictionaryRef, @"associations" ) )selectassociationsArrayRef = (CFMutableArrayRef)fn CFDictionaryGetValue( queryDictionaryRef, @"associations" )if ( selectassociationsArrayRef )sqlAssociationCount = fn CFArrayGetCount( selectassociationsArrayRef )if ( sqlAssociationCount > 0 )fn CFStringAppend( mySQLString, @" WHERE " )for i = 0 to sqlAssociationCount - 1associationsDictionaryRef = (CFMutableDictionaryRef) fn CFArrayGetValueAtIndex( selectassociationsArrayRef, i )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( associationsDictionaryRef, @"lefttablealias" ))fn CFStringAppend( mySQLString, @"." )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( associationsDictionaryRef, @"leftcolumnname" ))/* * * Operator Meaning * a = b a is equal to b * a != b a is not equal to b * a < b a is less than b * a > b a is greater than b * a <= b a is less than or equal to b * a >= b a is greater than or equal to b * a IN (b, c) a is equal to either b or c * a NOT IN (b, c) a is equal to neither b nor c * a LIKE a is LIKE 'b%' * a NOT LIKE a is NOT LIKE 'b%' * * only equal ( = ) should be used with associations * associations are the JOINS in the SQL SELECT STATEMENT * */myOperator = (CFNumberRef)fn CFDictionaryGetValue(associationsDictionaryRef, @"operator")fn CFNumberGetValue( myOperator, fn CFNumberGetType(myOperator), @aOperator )select case aOperatorcase _isEqual : fn CFStringAppend( mySQLString, @" = " )case _isNotEqual : fn CFStringAppend( mySQLString, @" != " )case _isLessThan : fn CFStringAppend( mySQLString, @" < " )case _isGreaterThan : fn CFStringAppend( mySQLString, @" > " )case _isLessThanOrEqual : fn CFStringAppend( mySQLString, @" <= " )case _isGreaterThanOrEqual : fn CFStringAppend( mySQLString, @" >= " )case _isIn : fn CFStringAppend( mySQLString, @" IN " )case _isNotIn : fn CFStringAppend( mySQLString, @" NOT IN " )end selectfn CFRelease( myOperator )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( associationsDictionaryRef, @"righttablealias" ))fn CFStringAppend( mySQLString, @"." )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( associationsDictionaryRef, @"rightcolumnname" ))if i > 0 and i <= sqlTableCount - 1 then fn CFStringAppend( mySQLString, @" AND " )next iend ifend ifend ifif ( fn CFDictionaryContainsKey( queryDictionaryRef, @"filter" ))selectfilterArrayRef = (CFMutableArrayRef)fn CFDictionaryGetValue( queryDictionaryRef, @"filter" )if ( selectfilterArrayRef )sqlFilterCount = fn CFArrayGetCount( selectfilterArrayRef )if ( sqlFilterCount > 0 )if sqlFilterCount > 0 and sqlAssociationCount > 0 then fn CFStringAppend( mySQLString, @" AND " )if sqlFilterCount > 0 and sqlAssociationCount = 0 then fn CFStringAppend( mySQLString, @" WHERE " )for i = 0 to sqlFilterCount - 1/* * * Logic Meaning * _and AND * _or OR * */filterDictionaryRef = (CFMutableDictionaryRef) fn CFArrayGetValueAtIndex( selectfilterArrayRef, i )if ( fn CFDictionaryContainsKey( filterDictionaryRef, @"logic" ) )columnLogic = (CFNumberRef)fn CFDictionaryGetValue( filterDictionaryRef, @"logic" )fn CFNumberGetValue( columnLogic, fn CFNumberGetType( columnLogic ), @aLogic )select case aLogiccase _andif i > 0 and i <= sqlFilterCount - 1 then fn CFStringAppend( mySQLString, @" AND " )case _orif i > 0 and i <= sqlFilterCount - 1 then fn CFStringAppend( mySQLString, @" OR " )end selectfn CFRelease( columnLogic )end iffn CFStringAppend( mySQLString, fn CFDictionaryGetValue( filterDictionaryRef, @"tablealias" ))fn CFStringAppend( mySQLString, @".")fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( filterDictionaryRef, @"columnname" ))/* * * Operator Meaning * a = b a is equal to b * a != b a is not equal to b * a < b a is less than b * a > b a is greater than b * a <= b a is less than or equal to b * a >= b a is greater than or equal to b * a IN (b, c) a is equal to either b or c * a NOT IN (b, c) a is equal to neither b nor c * * only equal ( = ) should be used with associations * associations are the JOINS in the SQL SELECT STATEMENT * */myOperator = (CFNumberRef)fn CFDictionaryGetValue( filterDictionaryRef, @"operator" )fn CFNumberGetValue( myOperator, fn CFNumberGetType( myOperator ), @aOperator )select case aOperatorcase _isEqual : fn CFStringAppend( mySQLString, @" = " ) : fn CFStringAppend(mySQLString, @" ? " )case _isNotEqual : fn CFStringAppend( mySQLString, @" != " ) : fn CFStringAppend(mySQLString, @" ? " )case _isLessThan : fn CFStringAppend( mySQLString, @" < " ) : fn CFStringAppend(mySQLString, @" ? " )case _isGreaterThan : fn CFStringAppend( mySQLString, @" > " ) : fn CFStringAppend(mySQLString, @" ? " )case _isLessThanOrEqual : fn CFStringAppend( mySQLString, @" <= " ) : fn CFStringAppend(mySQLString, @" ? " )case _isGreaterThanOrEqual : fn CFStringAppend( mySQLString, @" >= " ) : fn CFStringAppend(mySQLString, @" ? " )case _isIn : fn CFStringAppend( mySQLString, @" IN " ) : fn CFStringAppend( mySQLString, @" ? " )case _isNotIn : fn CFStringAppend( mySQLString, @" NOT IN " ) : fn CFStringAppend( mySQLString, @" ? " )case _isNull : fn CFStringAppend( mySQLString, @" ISNULL " )case _isNotNull : fn CFStringAppend( mySQLString, @" NOTNULL " )case _isLike : fn CFStringAppend( mySQLString, @" LIKE " ) : fn CFStringAppend( mySQLString, @" ? " )case _isNotLike : fn CFStringAppend( mySQLString, @" NOT LIKE " ) : fn CFStringAppend( mySQLString, @" ? " )end selectfn CFRelease( myOperator )next iend ifend ifend ifend fn = mySQLStringlocal modedim as CFMutableArrayRef selectcolsArrayRef, selecttablesArrayRef, selectassociationsArrayRef, selectfilterArrayRefdim as CFMutableDictionaryRef columnDictionaryRef, tableDictionaryRef, associationsDictionaryRef, filterDictionaryRefdim as CFMutableStringRef mySQLStringdim as CFIndex sqlColumnCount, sqlTableCount, sqlAssociationCount, sqlFilterCount, idim as CFNumberRef myOperator, columnLogicdim as long aOperator, aLogiclocal fn GenerateDeleteFromSQL( queryDictionaryRef as CFMutableDictionaryRef ) as CFMutableStringRef'~'1mySQLString = fn CFStringCreateMutable( _kCFAllocatorDefault, _noNaxCharacters )fn CFStringAppend( mySQLString, @"SELECT " )if ( fn CFDictionaryContainsKey( queryDictionaryRef, @"selectcols" ) )selectcolsArrayRef = (CFMutableArrayRef)fn CFDictionaryGetValue( queryDictionaryRef, @"selectcols" )if ( selectcolsArrayRef )sqlColumnCount = fn CFArrayGetCount( selectcolsArrayRef )for i = 0 to sqlColumnCount - 1columnDictionaryRef = (CFMutableDictionaryRef) fn CFArrayGetValueAtIndex( selectcolsArrayRef, i )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( columnDictionaryRef, @"columnname" ))fn CFStringAppend( mySQLString, @" AS ")fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( columnDictionaryRef, @"aliasname" ))if ( i < sqlColumnCount - 1 ) then fn CFStringAppend( mySQLString, @", " )next iend ifend iffn CFStringAppend( mySQLString, @" FROM " )if ( fn CFDictionaryContainsKey( queryDictionaryRef, @"selecttables" ) )selecttablesArrayRef = (CFMutableArrayRef)fn CFDictionaryGetValue( queryDictionaryRef, @"selecttables" )if ( selecttablesArrayRef )sqlTableCount = fn CFArrayGetCount( selecttablesArrayRef )for i = 0 to sqlTableCount - 1tableDictionaryRef = (CFMutableDictionaryRef) fn CFArrayGetValueAtIndex( selecttablesArrayRef, i )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( tableDictionaryRef, @"tablename" ))fn CFStringAppend( mySQLString, @" AS " )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( tableDictionaryRef, @"aliasname" ))if ( i < sqlTableCount - 1 ) then fn CFStringAppend( mySQLString, @", " )next iend ifend ifif ( fn CFDictionaryContainsKey( queryDictionaryRef, @"associations" ) )selectassociationsArrayRef = (CFMutableArrayRef)fn CFDictionaryGetValue( queryDictionaryRef, @"associations" )if ( selectassociationsArrayRef )sqlAssociationCount = fn CFArrayGetCount( selectassociationsArrayRef )if ( sqlAssociationCount > 0 )fn CFStringAppend( mySQLString, @" WHERE " )for i = 0 to sqlAssociationCount - 1associationsDictionaryRef = (CFMutableDictionaryRef) fn CFArrayGetValueAtIndex( selectassociationsArrayRef, i )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( associationsDictionaryRef, @"lefttablealias" ))fn CFStringAppend( mySQLString, @"." )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( associationsDictionaryRef, @"leftcolumnname" ))/* * * Operator Meaning * a = b a is equal to b * a != b a is not equal to b * a < b a is less than b * a > b a is greater than b * a <= b a is less than or equal to b * a >= b a is greater than or equal to b * a IN (b, c) a is equal to either b or c * a NOT IN (b, c) a is equal to neither b nor c * a LIKE a is LIKE 'b%' * a NOT LIKE a is NOT LIKE 'b%' * * only equal ( = ) should be used with associations * associations are the JOINS in the SQL SELECT STATEMENT * */myOperator = (CFNumberRef)fn CFDictionaryGetValue( associationsDictionaryRef, @"operator" )fn CFNumberGetValue( myOperator, fn CFNumberGetType( myOperator ), @aOperator )select case aOperatorcase _isEqual : fn CFStringAppend( mySQLString, @" = " )case _isNotEqual : fn CFStringAppend( mySQLString, @" != " )case _isLessThan : fn CFStringAppend( mySQLString, @" < " )case _isGreaterThan : fn CFStringAppend( mySQLString, @" > " )case _isLessThanOrEqual : fn CFStringAppend( mySQLString, @" <= " )case _isGreaterThanOrEqual : fn CFStringAppend( mySQLString, @" >= " )case _isIn : fn CFStringAppend( mySQLString, @" IN " )case _isNotIn : fn CFStringAppend( mySQLString, @" NOT IN " )end selectfn CFRelease( myOperator )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( associationsDictionaryRef, @"righttablealias" ))fn CFStringAppend( mySQLString, @"." )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( associationsDictionaryRef, @"rightcolumnname" ))if i > 0 and i <= sqlTableCount - 1 then fn CFStringAppend( mySQLString, @" AND " )next iend ifend ifend ifif ( fn CFDictionaryContainsKey( queryDictionaryRef, @"filter" ) )selectfilterArrayRef = (CFMutableArrayRef)fn CFDictionaryGetValue( queryDictionaryRef, @"filter" )if ( selectfilterArrayRef )sqlFilterCount = fn CFArrayGetCount( selectfilterArrayRef )if ( sqlFilterCount > 0 )if sqlFilterCount > 0 and sqlAssociationCount > 0 then fn CFStringAppend( mySQLString, @" AND " )if sqlFilterCount > 0 and sqlAssociationCount = 0 then fn CFStringAppend( mySQLString, @" WHERE " )for i = 0 to sqlFilterCount - 1/* * * Logic Meaning * _and AND * _or OR * */filterDictionaryRef = (CFMutableDictionaryRef) fn CFArrayGetValueAtIndex( selectfilterArrayRef, i )if ( fn CFDictionaryContainsKey( filterDictionaryRef, @"logic" ) )columnLogic = (CFNumberRef)fn CFDictionaryGetValue( filterDictionaryRef, @"logic" )fn CFNumberGetValue( columnLogic, fn CFNumberGetType( columnLogic), @aLogic )select case aLogiccase _andif i > 0 and i <= sqlFilterCount - 1 then fn CFStringAppend( mySQLString, @" AND " )case _orif i > 0 and i <= sqlFilterCount - 1 then fn CFStringAppend( mySQLString, @" OR " )end selectfn CFRelease( columnLogic )end iffn CFStringAppend( mySQLString, fn CFDictionaryGetValue( filterDictionaryRef, @"tablealias" ))fn CFStringAppend( mySQLString, @"." )fn CFStringAppend( mySQLString, fn CFDictionaryGetValue( filterDictionaryRef, @"columnname" ))/* * * Operator Meaning * a = b a is equal to b * a != b a is not equal to b * a < b a is less than b * a > b a is greater than b * a <= b a is less than or equal to b * a >= b a is greater than or equal to b * a IN (b, c) a is equal to either b or c * a NOT IN (b, c) a is equal to neither b nor c * * only equal ( = ) should be used with associations * associations are the JOINS in the SQL SELECT STATEMENT * */myOperator = (CFNumberRef)fn CFDictionaryGetValue( filterDictionaryRef, @"operator" )fn CFNumberGetValue( myOperator, fn CFNumberGetType( myOperator ), @aOperator )select case aOperatorcase _isEqual : fn CFStringAppend( mySQLString, @" = " ) : fn CFStringAppend( mySQLString, @" ? " )case _isNotEqual : fn CFStringAppend( mySQLString, @" != " ) : fn CFStringAppend( mySQLString, @" ? " )case _isLessThan : fn CFStringAppend( mySQLString, @" < " ) : fn CFStringAppend( mySQLString, @" ? " )case _isGreaterThan : fn CFStringAppend( mySQLString, @" > " ) : fn CFStringAppend( mySQLString, @" ? " )case _isLessThanOrEqual : fn CFStringAppend( mySQLString, @" <= " ) : fn CFStringAppend( mySQLString, @" ? " )case _isGreaterThanOrEqual : fn CFStringAppend( mySQLString, @" >= " ) : fn CFStringAppend( mySQLString, @" ? " )case _isIn : fn CFStringAppend( mySQLString, @" IN " ) : fn CFStringAppend( mySQLString, @" ? " )case _isNotIn : fn CFStringAppend( mySQLString, @" NOT IN " ) : fn CFStringAppend( mySQLString, @" ? " )case _isNull : fn CFStringAppend( mySQLString, @" ISNULL " )case _isNotNull : fn CFStringAppend( mySQLString, @" NOTNULL " )case _isLike : fn CFStringAppend( mySQLString, @" LIKE " ) : fn CFStringAppend( mySQLString, @" ? " )case _isNotLike : fn CFStringAppend( mySQLString, @" NOT LIKE ") : fn CFStringAppend( mySQLString, @" ? " )end selectfn CFRelease( myOperator )next iend ifend ifend ifend fn = mySQLStringlocal modedim as CFMutableDictionaryRef columnDictionaryRef, columnTypesDictionaryRefdim as CFMutableStringRef mySQLString, myValuesStringdim as CFIndex insertColumnCount, idim as EnumeratorRef columnEnumeratordim as CFStringRef columnNameRef, insertIntoTableStringReflocal fn GenerateInsertIntoSQL( insertDictionaryRef as CFMutableDictionaryRef ) as CFMutableStringRef'~'1mySQLString = fn CFStringCreateMutable( _kCFAllocatorDefault, _noNaxCharacters )/* * Append INSERT INTO <TABLE NAME> ( * */fn CFStringAppend( mySQLString, @"INSERT INTO " )if ( fn CFDictionaryContainsKey( insertDictionaryRef, @"insertintotable" ) )insertIntoTableStringRef = (CFMutableStringRef)fn CFDictionaryGetValue( insertDictionaryRef, @"insertintotable" )if ( insertIntoTableStringRef )fn CFStringAppend( mySQLString, insertIntoTableStringRef ) ' INSERT INTO <TABLE NAME>fn CFStringAppend( mySQLString, @" ( " ) ' INSERT INTO <TABLE NAME> (// fn CFRelease( insertIntoTableStringRef )end ifend if/* * insertcols * columntypes * */myValuesString = fn CFStringCreateMutable( _kCFAllocatorDefault, _noNaxCharacters )fn CFStringAppend(myValuesString, @" ) VALUES ( ")if ( fn CFDictionaryContainsKey( insertDictionaryRef, @"insertcols" ) )columnDictionaryRef = (CFMutableDictionaryRef)fn CFDictionaryGetValue( insertDictionaryRef, @"insertcols" )if ( columnDictionaryRef )insertColumnCount = fn CFDictionaryGetCount( columnDictionaryRef )if ( fn CFDictionaryContainsKey( insertDictionaryRef, @"columntypes" ))columnTypesDictionaryRef = (CFMutableDictionaryRef)fn CFDictionaryGetValue( insertDictionaryRef, @"columntypes" )if ( columnTypesDictionaryRef )columnEnumerator = fn DictionaryKeyEnumerator( columnDictionaryRef )columnNameRef = (CFStringRef)fn EnumeratorNextObject( columnEnumerator )i = 0while ( columnNameRef )i++// NSLog(@"%@",key)// fn CFDictionaryGetValue( columnDictionaryRef, columnNameRef )fn CFStringAppend( mySQLString, columnNameRef )if (i < insertColumnCount ) then fn CFStringAppend( mySQLString, @", " )fn CFStringAppend( myValuesString, @"? " )if (i < insertColumnCount ) then fn CFStringAppend( myValuesString, @", " )/*select case columnTypecase _nullTypecase _integerTypecase _realTypecase _textTypecase _blobTypeend select*/columnNameRef = (CFStringRef)fn EnumeratorNextObject( columnEnumerator )wendfn CFStringAppend( myValuesString, @" ) " )fn CFStringAppend( mySQLString, myValuesString )end ifend ifend ifend ifif ( myValuesString != NULL ) then fn CFRelease( myValuesString )end fn = mySQLString