dbTalk Databases Forums  

result::types(unsigned int) segmentation fault

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss result::types(unsigned int) segmentation fault in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Christopher
 
Posts: n/a

Default result::types(unsigned int) segmentation fault - 04-18-2005 , 05:03 PM






I made a test program using the tutorial code and it compiled and ran
fine on one machine. Then when I transfered the source to another
machine and compiled I consistantly get segmentation faults on any call
to result::types(unsigned int). The source hasn't changed at all. Also
the description on the fields came out all decimal null instead of what
they really were(mostly strings).
What could be the reason for this?

the source:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <mysql++.h>

using namespace std;
using namespace mysqlpp;

void Run_mysql();

int main()
{
try
{
Run_mysql();
}
catch(BadQuery er)
{
// handle any connection or query errors that may come up
cerr << "Error: " << er.error << endl;
return -1;
}

catch(BadConversion er)
{
// handle bad conversions
cerr << "Error: Tried to convert \"" << er.data << "\" to a \""<<
er.type_name << "\"." << endl;
return -1;
}

return 0;
}

void Run_mysql()
{
ofstream out("output.txt");

Connection connection(use_exceptions);

connection.connect("cp1119", "sentry.cs.txstate.edu", "cp1119",
"*******");

// Create a query object that is bound to connection.
Query query = connection.query();

// Write the query like you would any other ostream
query << "select * from GRADES";

// Execute the query and returns the results
Result result = query.store();

// Display the current query
out << "Query: " << query.preview() << endl;

// How many records were there
out << "Records Found: " << result.size() << endl << endl;

// The Result class has a read-only Random Access Iterator

// Get field info
out << "Query Info:\n";
out.setf(ios::left);

for(int i = 0; i < result.num_fields(); i++)
{
out << setw(3) << i

// this is the name of the field
<< setw(15) << result.names(i).c_str()

// this is the SQL identifier name
// Result::types(unsigned int) returns a mysql_type_info
which in many
// ways is like type_info except that it has additional sql type

// information in it. (with one of the methods being sql_name())
<< setw(20) << result.types(i).sql_name()

// this is the C++ identifier name which most closely resembles
// the sql name (its is implementation defined and often not
very readable)
<< setw(20) << result.types(i).name() << endl;
}
out<<endl;

// Compare mysql_type_info with a c++ type_info.
if(result.types(0).base_type() == typeid(string))
out << "Field 0 is of an sql type which most closely resembles the
c++ string type\n";

if(result.types(3).base_type() == typeid(float))
out << "Field 2 is of an sql type which most closely resembles the
c++ short int type\n";
out<<endl;

// Display the header info
for(int i = 0; i < result.num_fields(); i++)
out << setw(15) << result.names(i).c_str();
out<<endl;

// Display the data
Row row;
for(Result::iterator j = result.begin(); j != result.end(); j++)
{
row = *j;

for(int j = 0; j < result.num_fields(); j++)
out << setw(15) << row[j].c_str();
out<<endl;
}
}


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.