Back to index

lshw  02.16
Public Member Functions | Private Member Functions | Private Attributes
sqlite::statement Class Reference

#include <db.h>

Collaboration diagram for sqlite::statement:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 statement (database &, const std::string &)
 ~statement ()
void prepare (const std::string &)
void bind (int index, const value &v)
bool step ()
void execute ()
void reset ()
int columns () const
value column (unsigned int) const
value column (const std::string &) const
value operator[] (unsigned int) const
value operator[] (const std::string &) const

Private Member Functions

 statement ()
 statement (const statement &)
statementoperator= (const statement &)

Private Attributes

struct statement_iimplementation

Detailed Description

Definition at line 61 of file db.h.


Constructor & Destructor Documentation

statement::statement ( database db,
const std::string &  s 
)

Definition at line 269 of file db.cc.

{
  implementation = new statement_i;

  if(!implementation)
    throw exception("memory exhausted");

  implementation->db = &db;
  if(!db.implementation)
    throw exception("invalid database");

  if(sqlite3_prepare(db.implementation->connection, s.c_str(), -1, &implementation->stmt, NULL) != SQLITE_OK)
    throw exception(db.implementation->connection);
}

Definition at line 284 of file db.cc.

{
  if(implementation)
  {
    if(implementation->stmt)
      sqlite3_finalize(implementation->stmt);

    delete implementation;
  }
}
sqlite::statement::statement ( const statement ) [private]

Member Function Documentation

void statement::bind ( int  index,
const value v 
)

Definition at line 312 of file db.cc.

{
  if(!implementation)
    throw exception("undefined statement");

  switch(v.getType())
  {
    case null:
        if(sqlite3_bind_null(implementation->stmt, index) != SQLITE_OK)
         throw exception(implementation->db->implementation->connection);
       break;
    case text:
        if(sqlite3_bind_text(implementation->stmt, index, v.asText().c_str(), -1, SQLITE_TRANSIENT) != SQLITE_OK)
         throw exception(implementation->db->implementation->connection);
       break;
    case blob:
       {
          string blob = v.asText();
          if(sqlite3_bind_text(implementation->stmt, index, blob.data(), blob.size(), SQLITE_TRANSIENT) != SQLITE_OK)
           throw exception(implementation->db->implementation->connection);
         break;
       }
    case integer:
        if(sqlite3_bind_int64(implementation->stmt, index, v.asInteger()) != SQLITE_OK)
         throw exception(implementation->db->implementation->connection);
       break;
    case real:
        if(sqlite3_bind_double(implementation->stmt, index, v.asReal()) != SQLITE_OK)
         throw exception(implementation->db->implementation->connection);
       break;
    default:
       throw exception("unknown type");
  }
}

Here is the call graph for this function:

value statement::column ( unsigned int  i) const

Definition at line 381 of file db.cc.

{
  if(!implementation)
    throw exception("undefined statement");

  switch(sqlite3_column_type(implementation->stmt, i))
  {
    case SQLITE_INTEGER:
       return value(sqlite3_column_int64(implementation->stmt, i));
    case SQLITE_FLOAT:
       return value(sqlite3_column_double(implementation->stmt, i));
    case SQLITE_TEXT:
       return value((const char*)sqlite3_column_text(implementation->stmt, i));
    case SQLITE_BLOB:
    case SQLITE_NULL:
    default:
       return value();
  }
}

Here is the caller graph for this function:

value statement::column ( const std::string &  name) const

Definition at line 401 of file db.cc.

{
  if(!implementation)
    throw exception("undefined statement");

  for(int i=0; i<columns(); i++)
    if(strcasecmp(sqlite3_column_name(implementation->stmt, i), name.c_str())==0)
      return column(i);

  return value();
}

Here is the call graph for this function:

int statement::columns ( ) const

Definition at line 373 of file db.cc.

{
  if(!implementation)
    throw exception("undefined statement");

  return sqlite3_column_count(implementation->stmt);
}

Here is the caller graph for this function:

Definition at line 360 of file db.cc.

{
  while(step());
}

Here is the call graph for this function:

Here is the caller graph for this function:

statement& sqlite::statement::operator= ( const statement ) [private]
value statement::operator[] ( unsigned int  i) const

Definition at line 413 of file db.cc.

{
  return column(i);
}

Here is the call graph for this function:

value statement::operator[] ( const std::string &  i) const

Definition at line 418 of file db.cc.

{
  return column(i);
}

Here is the call graph for this function:

void statement::prepare ( const std::string &  s)

Definition at line 295 of file db.cc.

{
  if(implementation)
  {
    if(implementation->stmt)
      sqlite3_finalize(implementation->stmt);
  }
  else
    implementation = new statement_i;

  if(!implementation)
    throw exception("memory exhausted");

  if(sqlite3_prepare(implementation->db->implementation->connection, s.c_str(), -1, &implementation->stmt, NULL) != SQLITE_OK)
    throw exception(implementation->db->implementation->connection);
}
void statement::reset ( )

Definition at line 365 of file db.cc.

{
  if(!implementation)
    throw exception("undefined statement");

  sqlite3_reset(implementation->stmt);    // ignore return value
}
bool statement::step ( )

Definition at line 347 of file db.cc.

{
  if(!implementation)
    throw exception("undefined statement");

  int result = sqlite3_step(implementation->stmt);

  if(result == SQLITE_DONE) return false;
  if(result == SQLITE_ROW) return true;

  throw exception(implementation->db->implementation->connection);
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 88 of file db.h.


The documentation for this class was generated from the following files: