Re: Inserting a BLOB using MySQL++

2002-04-22 Thread Sinisa Milivojevic

Thi Cao writes:
 All,
 
 I created a C++ class containing a variety of member variables of varying
 types such as float, int, char *, etc.  If I instantiate an object of this
 class, how should I insert this object into my database table?  I can
 retrieve the individual members and insert them that way, but I feel it
 would be more efficient to insert the object as a BLOB, but I don't exactly
 know how to do that.  Basically, I want to insert the object as is so that I
 can retrieve it as is and not have to bother with calling the member setting
 functions to populate the class members.  I looked at the MySQL++ example
 for loading a binary file, but am unsure how to apply that to my needs.  I
 also looked through the mail archives and was unsuccessful in finding a
 solution, so any assistance would be much appreciated.  Thanks in advance.
 
 Regards,
 
 Thi

Hi!

Take a look in reset_db.cc and load_file.cc example files.

In any case, you always have to escape a binary string prior to
inserting it. 

As it is seen in cgi_image.cc example, you will always get back from
MySQL your BLOB in en-escaped, original form.

-- 
Regards,
   __  ___ ___   __
  /  |/  /_ __/ __/ __ \/ /Mr. Sinisa Milivojevic [EMAIL PROTECTED]
 / /|_/ / // /\ \/ /_/ / /__   MySQL AB, Fulltime Developer
/_/  /_/\_, /___/\___\_\___/   Larnaca, Cyprus
   ___/   www.mysql.com


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: Inserting a BLOB using MySQL++

2002-04-22 Thread Opus

Probably the best bet would be to write the individual attributes to respective 
database columns.  It keeps a few things simpler.  It would also allow you to 
update the database from multible sources (many threads, or many users on the 
database).

Other wise, you would have to serialize the object to a binary object and write 
that to the BLOB field.  When you imported it back, you would have to 
deserialize.  Some languages call this pickeling.  As I have not touched C++ 
code for a while, I'm not sure what classes are availible to do this for you.

The BLOB way of doing it would force you read/write the entire thing everytime 
you update the object, unless you are just using the database to store it for 
backup.

-Opus

On 22 Apr 2002 at 8:21, Thi Cao wrote:

 All,
 
 I created a C++ class containing a variety of member variables of varying
 types such as float, int, char *, etc.  If I instantiate an object of this
 class, how should I insert this object into my database table?  I can
 retrieve the individual members and insert them that way, but I feel it
 would be more efficient to insert the object as a BLOB, but I don't exactly
 know how to do that.  Basically, I want to insert the object as is so that I
 can retrieve it as is and not have to bother with calling the member setting
 functions to populate the class members.  I looked at the MySQL++ example
 for loading a binary file, but am unsure how to apply that to my needs.  I
 also looked through the mail archives and was unsuccessful in finding a
 solution, so any assistance would be much appreciated.  Thanks in advance.
 
 Regards,
 
 Thi
 


--Opus--

Government is not reason, it is not eloquence- it is force.
- George Washington


Get added to my Humor list:
mailto:[EMAIL PROTECTED]?subject=ADD_HUMOR
Get added to my Neat list:
mailto:[EMAIL PROTECTED]?subject=ADD_NEAT
Get my PGP public key:
mailto:[EMAIL PROTECTED]?subject=PSENDbody=send%20PublicKEY.asc
Visit My Home Page:
http://value.net/~opus/




-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php