Re: [sqlite] Help with establishing a connection on NS3 and sqlite DB

2017-03-22 Thread Dan Kennedy

On 03/22/2017 05:58 AM, Ausama Majeed wrote:

Hello guys,

I am trying to do a connection between a database created with Sqlite and
my application in ns3. the sqlite engine is installed on ubuntu 16.04
machine and the output is enabled with ns3.26. I cann't do a simple select
query from ns3, however it working through the terminal.
I install sqlite-autoconf-317 as API to deal with the database.

the BD is opened successfully in the fallowing code:

sqlite3 *db;
 int rc;
 char *error = 0;
 rc = sqlite3_open("/home/mypc/Desktop/ns-3.26/ns-3.26/testDB.db", );
 if (rc) {
 cerr << "Error opening SQLite3 database: " << sqlite3_errmsg(db) <<
endl << endl;
 sqlite3_close(db);
 return 1;
 } else {
 cout << "\n Successfully connected to the database \n";
 int n = 0;
 cin >> n;
 // Print this info

  cout << GARIComposeAlgo(db, error, n);
 cout << "\nclose the db\n";
 sqlite3_close(db);
}


But, select query returns only the table field headers instead of the
required record   in the following code


As expected, I think. If your SELECT statement returns N rows of M 
columns, get_table() gives you an array of (N+1)*M nul-terminated 
strings. The first M strings in the array are the column headers, the 
next M are the first row of results, and so on.


  https://sqlite.org/c3ref/free_table.html

Dan.






string Query = " select ActorId, ActorType from ActorInfo where ID =" +
tempProcess.str() +";";


 char **results = NULL;
 int rows, columns;
 const char *sqlSelect = Query.c_str();
 int rc;
 rc = sqlite3_get_table(db, sqlSelect, , , ,
);
 if (rc != SQLITE_OK) {
 cerr << "Error executing SQLite3 query: " << sqlite3_errmsg(db) <<
endl << endl;
 sqlite3_free(error);
 }
 else {
for (int i= 0; i<4; i++) {cout << results[i]<< endl;}
}

Could anyone advice me what could the problem and how to check it, solve it
please.

Thanks
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Help with establishing a connection on NS3 and sqlite DB

2017-03-21 Thread Simon Slavin

On 21 Mar 2017, at 10:58pm, Ausama Majeed  wrote:

> But, select query returns only the table field headers instead of the
> required record   in the following code
> 
> string Query = " select ActorId, ActorType from ActorInfo where ID =" +
> tempProcess.str() +";";

For debugging purposes, please have your program display the value of sqlSelect 
(or log it to an error channel, or some such thing) before it tries to execute 
it.  This will allow you to figure out whether you’re getting the right value 
for ID.

However, I suspect that you should worry more that you’re using 
sqlite3_get_table().  That’s an obsolete call and should not be used for new 
code. Instead use sqlite3_exec().

Simon.
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Help with establishing a connection on NS3 and sqlite DB

2017-03-21 Thread Ausama Majeed
Hello guys,

I am trying to do a connection between a database created with Sqlite and
my application in ns3. the sqlite engine is installed on ubuntu 16.04
machine and the output is enabled with ns3.26. I cann't do a simple select
query from ns3, however it working through the terminal.
I install sqlite-autoconf-317 as API to deal with the database.

the BD is opened successfully in the fallowing code:

sqlite3 *db;
int rc;
char *error = 0;
rc = sqlite3_open("/home/mypc/Desktop/ns-3.26/ns-3.26/testDB.db", );
if (rc) {
cerr << "Error opening SQLite3 database: " << sqlite3_errmsg(db) <<
endl << endl;
sqlite3_close(db);
return 1;
} else {
cout << "\n Successfully connected to the database \n";
int n = 0;
cin >> n;
// Print this info

 cout << GARIComposeAlgo(db, error, n);
cout << "\nclose the db\n";
sqlite3_close(db);
}


But, select query returns only the table field headers instead of the
required record   in the following code

string Query = " select ActorId, ActorType from ActorInfo where ID =" +
tempProcess.str() +";";


char **results = NULL;
int rows, columns;
const char *sqlSelect = Query.c_str();
int rc;
rc = sqlite3_get_table(db, sqlSelect, , , ,
);
if (rc != SQLITE_OK) {
cerr << "Error executing SQLite3 query: " << sqlite3_errmsg(db) <<
endl << endl;
sqlite3_free(error);
}
else {
   for (int i= 0; i<4; i++) {cout << results[i]<< endl;}
}

Could anyone advice me what could the problem and how to check it, solve it
please.

Thanks
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users