~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to examples/simple.cc

  • Committer: Mark Atwood
  • Date: 2011-08-21 06:58:08 UTC
  • mfrom: (2407.1.6 client)
  • Revision ID: me@mark.atwood.name-20110821065808-l3xxgvbreily086c
mergeĀ lp:~olafvdspek/drizzle/client

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
 
85
85
  drizzle::drizzle_c drizzle;
86
86
  drizzle::connection_c* con= new drizzle::connection_c(drizzle);
87
 
  con->set_tcp(host, port);
88
 
  con->set_auth(user, password);
 
87
  if (host || port)
 
88
    con->set_tcp(host, port);
 
89
  if (user || password)
 
90
    con->set_auth(user, password);
89
91
  con->set_db("information_schema");
90
 
  drizzle::result_c result;
91
92
  drizzle::query_c q(*con, "select table_schema, table_name from tables where table_name like ?");
92
93
  q.p("%");
93
 
  cout << q.read() << endl;
94
 
  if (q.execute(result))
95
 
  {
96
 
    cerr << "query: " << con->error() << endl;
 
94
  try
 
95
  {
 
96
    drizzle::result_c result= q.execute();
 
97
    cout << q.read() << endl;
 
98
    while (drizzle_row_t row= result.row_next())
 
99
    {
 
100
      for (int x= 0; x < result.column_count(); x++)
 
101
      {
 
102
        if (x)
 
103
          cout << ", ";
 
104
        cout << (row[x] ? row[x] : "NULL");
 
105
      }
 
106
      cout << endl;
 
107
    }
 
108
  }
 
109
  catch (const drizzle::bad_query& e)
 
110
  {
 
111
    cerr << e.what() << endl;
97
112
    return 1;
98
113
  }
99
 
  while (drizzle_row_t row= result.row_next())
100
 
  {
101
 
    for (int x= 0; x < result.column_count(); x++)
102
 
    {
103
 
      if (x)
104
 
        cout << ", ";
105
 
      cout << (row[x] ? row[x] : "NULL");
106
 
    }
107
 
    cout << endl;
108
 
  }
109
114
  return 0;
110
115
}