[odb-users] Output of native SQL statement in SQLite.

Tenneti, Rohith UTC CCS Rohith.Tenneti at fs.utc.com
Mon Jan 9 11:29:57 EST 2017


Hello,

Thanks for the reply, but ODB compiler gives an error with 

1.
    #pragma db view query("PRAGMA integrity_check")
    struct integrity_check
    {
        std::string problem;
    };

    error: view '::integrity_check' has an incomplete query template and no associated objects
    info: use db pragma query to provide a complete query template
    info: or use db pragma object to associate one or more objects with the view

2. 
I then tried,
    #pragma db view
    struct integrity_check
    {
        std::string problem;
    };

  db->query < integrity_check >( "PRAGMA integrity_check" );

 Which of course then resulted in a run time error at the PREPARE level as the query being executed was "WHERE PRAGMA integrity_check".



Thank You

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Monday, January 09, 2017 9:22 AM
To: Tenneti, Rohith UTC CCS
Cc: odb-users at codesynthesis.com
Subject: [External] Re: [odb-users] Output of native SQL statement in SQLite.

Hi Rohith,

Tenneti, Rohith UTC CCS <Rohith.Tenneti at fs.utc.com> writes:

> I am trying to capture the output of SQL statement in SQLite "PRAGMA 
> integrity_check;" using :
> 
>         session s;
>         transaction t( db->begin() );
> 
>         numRows = db->execute("PRAGMA integrity_check");
> 
>         t.commit();

According to the SQLite documentation, "If the integrity_check pragma finds problems, strings are returned (as multiple rows with a single column per
row) which describe the problems. If pragma integrity_check finds no errors, a single row with the value 'ok' is returned."

So in a sense it behaves like SELECT which means you can use a view to get the result:

#pragma db view query("PRAGMA integrity_check") struct integrity_check {
  std::string problem;
};

for (const integrity_check& ic: db.query<integrity_check> ()) {
  cerr << ic.problem << endl;
}

Boris



More information about the odb-users mailing list