How to find the no. of elements for a char * string
Manoj
manojkarekar@rediffmail.com
Thu Dec 28 00:43:00 GMT 2000
Hi,
I am using mysql database and its C++ APIs.
In database table I have defined a medium blob column.
If the column contains embeded '\0' i.e NULL characters
then the result gets truncated after the first occurance
of '\0'. Here the result is taken in string data type using fetch_row API of mysql.
Othe way of doing it is initialize a string of size(this size will be the length of the medium blob column contents.) and const char* as arguments.
The tried example is given below.
=========================================================
#include<iostream.h>
#include<string>
#include"EzeeDB.h" //mysql API
main()
{
string query = "select content,length(content)
from ContentTbl where urlId = 999";
EzeeDB handle("general","192.168.1.7",3306,"","",ON);
handle.Connect();
Result result;
handle.ExecuteSelect(query,result);
MYSQL_RES *my_result = result.mysql_result();
uint i = 0;
uint length = atoi(my_result->data->data->data[1]);
cout<<length<<endl;
string contents(my_result->data->data->data[0],length);
cout<<contents.length()<<endl;
for(i=0; i<contents.length(); i++)
cout<<contents[i];
cout<<endl;
}
=========================================================
But the problem with this approach is if the string is initialized with a length which is higher than the
allocated memory for char* then it results in erroneous
output ,may crash with segmentation fault.
Suggest a method to read the contents of a medium blob
containing embeded '\0' characters.
regards
Manoj
<manojkarekar@rediffmail.com>
_____________________________________________________
Chat with your friends as soon as they come online. Get Rediff Bol at
http://bol.rediff.com
More information about the Gcc-help
mailing list