![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I wanted to read and write a C++ structure to the DB. I went through the example given and from this sinppet of code I got from the user mannual, had a small Q. I thought that std::string is a /0 delimited string, if so, how does this work? If the binary data has a /0 inbetween somwhere in there, wouldnt the string fill be shortened when pushed into the strbuf? ostringstream strbuf; char *read_buffer = new char[blen]; In.read(read_buffer, blen); string fill(read_buffer, blen); strbuf << "INSERT INTO " << MY_TABLE << " (" << MY_FIELD << ") VALUES(\"" << mysqlpp::escape << fill << "\")" << ends; Thanks Ankur |
#3
| |||
| |||
|
|
Hi, I wanted to read and write a C++ structure to the DB. |
#4
| |||
| |||
|
|
Ankur G35 Saxena wrote: Hi, I wanted to read and write a C++ structure to the DB. |
#5
| |||
| |||
|
|
Ankur G35 Saxena wrote: Hi, I wanted to read and write a C++ structure to the DB. Bad, bad idea. For this to be guaranteed to work, you could never upgrade your compiler version or change compilers. You can't even change some compiler options even if you were willing to stick with a single compiler, because there are options that will change the binary layout of your classes. Do a Google search for object serialization in C++. There are ways to get around this problem, many of which will solve the BLOB problem as a side effect. I can recommend ICE. I have successfully used ICE by ZeroC to |
|
Or, switch to a language that understands things like serialization and reflection. This is one of the things that C++ is just not good at. |
![]() |
| Thread Tools | |
| Display Modes | |
| |