Help with establishing a connection on NS3 and sqlite DB

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Help with establishing a connection on NS3 and sqlite DB

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-3170000 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", &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, &results, &rows, &columns,
&error);
    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
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Simon Slavin-3

On 21 Mar 2017, at 10:58pm, Ausama Majeed <[hidden email]> 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
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Dan Kennedy-4
In reply to this post by Ausama Majeed
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-3170000 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", &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, &results, &rows, &columns,
> &error);
>      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
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Loading...