File: complete.cpp

package info (click to toggle)
simpledb 1.5-1.4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, squeeze
  • size: 888 kB
  • ctags: 238
  • sloc: cpp: 529; makefile: 127; perl: 23; sh: 9
file content (30 lines) | stat: -rw-r--r-- 1,091 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "SimpleDB/SimpleDB.h"

int main() {
  SimpleDB::LongColumn id = SimpleDB::LongColumn();
  SimpleDB::StringColumn name = SimpleDB::StringColumn(1000);
  SimpleDB::Column * columns[2] = {&id,&name};
  
  try {
    SimpleDB::Database db = SimpleDB::Database("eminence");    
    SimpleDB::Query query = db.newQuery();
    query.bind(columns, sizeof(columns)/sizeof(columns[0]));
    query.execute("SELECT contact_number, first_name FROM contacts LIMIT 10");
    
    while(query.fetchRow())
      std::cout << "ID: " << *columns[0] << " NAME: " << *columns[1] << std::endl;
    
    query.execute("SELECT contact_number, last_name FROM contacts LIMIT 5");
    while(query.fetchRow()) {
      std::cout << "ID: " << *columns[0] << " NAME: " << *columns[1] << std::endl;
      std::cout << "Some math " << id.value()*5 << " " << name.value().append(" adfad") <<
	std::endl;
    }
  } catch(SimpleDB::Database::Exception &s) {
    std::cerr << s << std::endl;
  } catch(SimpleDB::Column::UnboundException) {
    std::cerr << "A column was not bound!" << std::endl;
  }
  return 0;
}