[Mysql-cocoa-commits] CVS: SMySQL MCPConnection.h,1.1.2.4,1.1.2.5 MCPConnection.m,1.1.2.6,1.1.2.7 MC
Brought to you by:
sergecohen
From: Serge C. <ser...@us...> - 2002-07-23 14:56:46
|
Update of /cvsroot/mysql-cocoa/SMySQL In directory usw-pr-cvs1:/tmp/cvs-serv7923 Modified Files: Tag: version-2 MCPConnection.h MCPConnection.m MCPResult.h MCPResult.m Log Message: Corrected version-2 for NULL field... should work now. Added the proper handling of year 0000 (default year for year out of ange from MySQL). Some line to log any thing to a file, commented out in the CVS tree. Serge Cohen; MySQL-Cocoa project 2002. Index: MCPConnection.h =================================================================== RCS file: /cvsroot/mysql-cocoa/SMySQL/Attic/MCPConnection.h,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** MCPConnection.h 3 Jun 2002 13:39:24 -0000 1.1.2.4 --- MCPConnection.h 23 Jul 2002 14:56:43 -0000 1.1.2.5 *************** *** 138,140 **** --- 138,145 ---- - (NSString *) stringWithCString:(const char *) theCString; + /*" + Text data convertion to string + "*/ + - (NSString *) stringWithText:(NSData *) theTextData; + @end Index: MCPConnection.m =================================================================== RCS file: /cvsroot/mysql-cocoa/SMySQL/Attic/MCPConnection.m,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -C2 -d -r1.1.2.6 -r1.1.2.7 *** MCPConnection.m 12 Jun 2002 16:20:38 -0000 1.1.2.6 --- MCPConnection.m 23 Jul 2002 14:56:43 -0000 1.1.2.7 *************** *** 32,35 **** --- 32,38 ---- const unsigned int kMCPConnection_Not_Inited = 1000; + // For debugging: + //static FILE *MCPConnectionLogFile; + @implementation MCPConnection *************** *** 117,120 **** --- 120,129 ---- [self setVersion:020000]; // Ma.Mi.Re -> MaMiRe } + + // For debugging: + /* + MCPConnectionLogFile = fopen("MCPConnection_debug.txt","a"); + NSLog(@"MCPConnectionLogFile = %p\n", MCPConnectionLogFile); + */ return; } *************** *** 271,274 **** --- 280,288 ---- } mEncoding = [MCPConnection encodingForMySQLEncoding:mysql_character_set_name(mConnection)]; + /* + NSLog (@"Default encoding is %@\n", [NSString localizedNameOfStringEncoding:[NSString defaultCStringEncoding]]); + NSLog (@"MySQL encoding is %@\n", [NSString localizedNameOfStringEncoding:mEncoding]); + fprintf(MCPConnectionLogFile,"MySQLEncoding : %s\n", (const char *)[[NSString localizedNameOfStringEncoding:mEncoding] cString]); + */ return mConnected = YES; } *************** *** 386,390 **** /*" Takes a query string and return an MCPResult object holding the result of the query. ! The returned MCPResult is not retained, the client is responsible for that (it's autoreleased before being returned). If no field are present in the result (like in an insert query), will return nil (!{difference from previous version implementation}). Note that if you want to use this method with binary data (in the query), you should use #{prepareBinaryData:} to include the binary data in the query string. Also if you want to include in your query a string containing any special character (\, ', " ...) then you should use #{prepareString}. --- 400,404 ---- /*" Takes a query string and return an MCPResult object holding the result of the query. ! The returned MCPResult is not retained, the client is responsible for that (it's autoreleased before being returned). If no field are present in the result (like in an insert query), will return nil (!{difference from previous version implementation}). Though, if their is at least one field the result will be non nil (even if no row are selected). Note that if you want to use this method with binary data (in the query), you should use #{prepareBinaryData:} to include the binary data in the query string. Also if you want to include in your query a string containing any special character (\, ', " ...) then you should use #{prepareString}. *************** *** 394,398 **** --- 408,432 ---- const char *theCQuery = [self cStringFromString:query]; int theQueryCode; + // Temp for debugging: + /* + NSMutableData *theDefCQuery = [NSMutableData dataWithData:[query dataUsingEncoding:[NSString defaultCStringEncoding] allowLossyConversion:YES]]; + NSMutableData *theIso1CQuery = [NSMutableData dataWithData:[query dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:YES]]; + const char *theDCQuery, *theICQuery; + [theDefCQuery increaseLengthBy:1]; + [theIso1CQuery increaseLengthBy:1]; + theDCQuery = [theDefCQuery bytes]; + theICQuery = [theIso1CQuery bytes]; + */ + // NSLog (@"In queryString, query is : %s -in ObjC : %@-\n", theCQuery, query); + /* + fprintf(MCPConnectionLogFile,"C string (MySQL enco.) : "); + fwrite((const void *)theCQuery, strlen(theCQuery), 1, MCPConnectionLogFile); + fprintf(MCPConnectionLogFile,"\nC string (default enco.) : "); + fwrite((const void *)theDCQuery, strlen(theDCQuery), 1, MCPConnectionLogFile); + fprintf(MCPConnectionLogFile,"\nC string (iso1 enco.) : "); + fwrite((const void *)theICQuery, strlen(theICQuery), 1, MCPConnectionLogFile); + fprintf(MCPConnectionLogFile,"\n"); + */ if ((theQueryCode = mysql_query(mConnection, theCQuery)) == NULL) { if (mysql_field_count(mConnection) != 0) { *************** *** 753,756 **** --- 787,809 ---- return theString; } + + + - (NSString *) stringWithText:(NSData *) theTextData + /*" + Use the string encoding to convert the returned NSData to a string (for a Text field) + "*/ + { + NSString * theString; + + if (theTextData == nil) { + return nil; + } + theString = [[NSString alloc] initWithData:theTextData encoding:mEncoding]; + if (theString) { + [theString autorelease]; + } + return theString; + } + @end Index: MCPResult.h =================================================================== RCS file: /cvsroot/mysql-cocoa/SMySQL/Attic/MCPResult.h,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** MCPResult.h 3 Jun 2002 13:39:24 -0000 1.1.2.4 --- MCPResult.h 23 Jul 2002 14:56:43 -0000 1.1.2.5 *************** *** 82,85 **** --- 82,90 ---- /*" + Text data convertion to string + "*/ + - (NSString *) stringWithText:(NSData *) theTextData; + + /*" Utility method "*/ *************** *** 93,97 **** /*" ! Private methods, internam use only "*/ - (const char *) cStringFromString:(NSString *) theString; --- 98,102 ---- /*" ! Private methods, internal use only "*/ - (const char *) cStringFromString:(NSString *) theString; Index: MCPResult.m =================================================================== RCS file: /cvsroot/mysql-cocoa/SMySQL/Attic/MCPResult.m,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -C2 -d -r1.1.2.5 -r1.1.2.6 *** MCPResult.m 12 Jun 2002 16:20:38 -0000 1.1.2.5 --- MCPResult.m 23 Jul 2002 14:56:43 -0000 1.1.2.6 *************** *** 30,33 **** --- 30,34 ---- #import "MCPResult.h" + NSCalendarDate *MCPYear0000; @implementation MCPResult *************** *** 69,72 **** --- 70,75 ---- if (self = [MCPResult class]) { [self setVersion:020000]; // Ma.Mi.Re -> MaMiRe + MCPYear0000 = [[NSCalendarDate dateWithTimeIntervalSinceReferenceDate:-63146822400.0] retain]; + [MCPYear0000 setCalendarFormat:@"%Y"]; } return; *************** *** 290,293 **** --- 293,304 ---- theCurrentObj = [NSCalendarDate dateWithString:[NSString stringWithCString:theData] calendarFormat:@"%Y"]; [theCurrentObj setCalendarFormat:@"%Y"]; + // MySQL is not able to save years before 1900, and then gives a column of 0000, unfortunately, NSCalendarDate + // doesn't accept the string @"0000" in the method datewithString: calendarFormat:@"%Y"... + if (! theCurrentObj) { + theCurrentObj = MCPYear0000; + } + // Debugging + // NSLog(@"The Yeear is : %@, the field is %s\n", theCurrentObj, theData); + // End break; case FIELD_TYPE_VAR_STRING: *************** *** 320,323 **** --- 331,338 ---- } free(theData); + // Some of the creators return nil object... + if (theCurrentObj == nil) { + theCurrentObj = [NSNull null]; + } } switch (aType) { *************** *** 617,621 **** Return YES if the field (by name) with the given index is a BLOB. It should be used to discriminates between BLOBs and TEXTs. ! #{NOT YET IMPLEMENTED}, return YES for both BLOBs and TEXTs... "*/ { --- 632,636 ---- Return YES if the field (by name) with the given index is a BLOB. It should be used to discriminates between BLOBs and TEXTs. ! !{NOT YET IMPLEMENTED}, return YES for both BLOBs and TEXTs... "*/ { *************** *** 653,656 **** --- 668,689 ---- } return theRet; + } + + + - (NSString *) stringWithText:(NSData *) theTextData + /*" + Use the string encoding to convert the returned NSData to a string (for a Text field) + "*/ + { + NSString * theString; + + if (theTextData == nil) { + return nil; + } + theString = [[NSString alloc] initWithData:theTextData encoding:mEncoding]; + if (theString) { + [theString autorelease]; + } + return theString; } |