public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to find the no. of elements for a char * string
@ 2000-12-28  0:43 Manoj
  0 siblings, 0 replies; only message in thread
From: Manoj @ 2000-12-28  0:43 UTC (permalink / raw)
  To: gcc-help

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




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-12-28  0:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-28  0:43 How to find the no. of elements for a char * string Manoj

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).