Re: [Mysql-cocoa-users] Blob ?
Brought to you by:
sergecohen
From: Serge C. <ser...@us...> - 2003-05-22 16:45:02
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Sorry I missed the previous post...=0D =0D You can as well use the method=0D - -(NSString *) stringWithText:(NSData *) theTextData=0D =0D from MCPConnection or MCPResult in this way:=0D =0D NSData* contentAsBlob =3D [lineRes objectForKey:@"theText"];=0D NSString* contentAsString =3D [lineRes stringWithText:contentAsBlob];=0D =0D The interest of this method is that it should be able to use a better =0D= (more proper) encoding, when you need to pass around characters out of =0D= the 7bit ASCII (accented characters...). For that it uses the encoding =0D= declared by the mysql server...=0D =0D Note that you can also change the second line to :=0D NSString* contentAsString =3D [theMCPConnection =0D stringWithText:contentAsBlob];=0D =0D It can be interesting if you get the blob without having access to the =0D= MCPResult but you still have access to a MCPConnection connected to the =0D= proper server.=0D =0D Last note, the encoding present for MySQL and from Apple does not =0D match... So in the current implementation I'm trying to use the Apple =0D= encoding closest to the one from MySQL. This mean that certain MySQL =0D encoding are not Ok (no Apple correspondance), some other are =0D incomplete...=0D =0D =0D Serge.=0D =0D =0D Le jeudi, 22 mai 2003, =E0 16:51 Europe/Amsterdam, John Guy a =E9crit :=0D= =0D > Sorry for the delay in getting back on this,=0D >=0D > I replied to a similar question a while ago, but basically if the =0D > column texte is in fact a BLOB, then what you will get back from the =0D= > query is NOT an NSString, but an NSData object.=0D >=0D > If you know that the NSData object actually contains string data then =0D= > you can extract a string from it using the raw data with an encoding =0D= > as below=0D >=0D > NSData* contentRawBlob =3D [lineRes objectForKey:@"value"];=0D > NSString* contentText =3D [[NSString alloc] = initWithData:contentRawBlob=0D > = encoding:NSASCIIStringEncoding];=0D >=0D >=0D > Hope this helps=0D >=0D > JOhn=0D >=0D >=0D >=0D > On Tuesday, May 20, 2003, at 05:38 AM, Camille Goureau-Suignard wrote:=0D= >=0D >> Hi,=0D >>=0D >> did anybody manage to retrieve a blob ?=0D >>=0D >> with string : "marotte ange"=0D >> chaine2 =3D [NSString stringWithFormat: @"insert =0D >> commentlong (texte) values (\"%@\") ;", [cnxCommentaireLong =0D >> stringValue]] ;=0D >>=0D >> it gives in MySQL :=0D >> mysql> select * from commentlong ;=0D >> +----+--------------+=0D >> | id | texte |=0D >> +----+--------------+=0D >> | 1 | marotte ange |=0D >> +----+--------------+=0D >> 1 row in set (0.05 sec)=0D >>=0D >> But when retrieving it it gives :=0D >> SMySQLResult *result2 =3D [connectMySQL queryString: =0D= >> [NSString stringWithFormat: @"select texte from commentlong where id =0D= >> =3D %@ ;",[ligne objectForKey: @"id_commentlong"]]] ;=0D >> [cnxCommentaireLong setStringValue: [[result2 =0D >> fetchRowAsDictionary] objectForKey: @"texte"]] ;=0D >>=0D >> <6d61726f 74746520 616e6765 >=0D >>=0D >> any idea ?=0D >>=0D >> Thanks.=0D >>=0D >> Camille=0D >>=0D >>=0D >>=0D >> -------------------------------------------------------=0D >> This SF.net email is sponsored by: ObjectStore.=0D >> If flattening out C++ or Java code to make your application fit in a=0D= >> relational database is painful, don't do it! Check out ObjectStore.=0D= >> Now part of Progress Software. http://www.objectstore.net/sourceforge=0D= >> _______________________________________________=0D >> Mysql-cocoa-users mailing list=0D >> Mys...@li...=0D >> https://lists.sourceforge.net/lists/listinfo/mysql-cocoa-users=0D >>=0D >>=0D - ----------------------------------------------------=0D Serge Cohen=0D =0D GPG Key ID: 9CBB58FB=0D - ----------------------------------------------------=0D -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (Darwin) iD8DBQE+zPao5EPeG5y7WPsRAhMrAKCTGH4gR6U77r5F56LJBXCHEjRJsgCg+wn/ Vd4AnukWy/hz4sYZEEN1RWY=3D =3Dqmwm -----END PGP SIGNATURE----- |