[Mysql-cocoa-users] Save and Read NSImage in mysql
Brought to you by:
sergecohen
|
From: Eric V. <ev...@cl...> - 2007-01-14 11:34:46
|
Hi,
i use the new version of the framework (3.01) to store int, varchar,
float and text without problem.
When i write a picture in a longblob (with a good max packet size)
and read it, my data length is double.
I have the following code to save picture :
MCPConnection *connection;
MCPResult *result;
NSString *nomFichier;
NSImage *image;
NSData *tiffData;
NSString *query;
int index, error;
NSArray *names;
NSDictionary *row;
nomFichier = [[NSString alloc] initWithString:@"~/Pictures/Mars.gif"];
nomFichier = [nomFichier stringByExpandingTildeInPath];
image = [[NSImage alloc] initWithContentsOfFile:nomFichier];
tiffData = [image TIFFRepresentation];
// 9402 bytes
string = [connection prepareBinaryData:tiffData];
index = 1;
query = [[NSString alloc] initWithFormat:@"Insert into %@ (%@, %@)
VALUES ('%@', %d);",
@"nomTable",
@"nomColonne",
@"nombre",
string,
index];
result = [connection queryString:query];
and the following code to read picture :
query = [[NSString alloc] initWithFormat:@"SELECT nomColonne
FROM nomTable WHERE nombre = %d;",
index];
result = [connection queryString:query];
names = [result fetchFieldNames];
error = [connexion getLastErrorID];
if (error == 0)
{
row = [result fetchRowAsDictionary];
tiffData = [row objectForKey:[names objectAtIndex:0]];
// 18804 bytes
}
I use 5.0.27 (32 and 64 bits PPC version) version with the same result.
Thank you in advance for your help,
Eric
|