Samchon Framework for CPP  1.0.0
sql.hpp
1 #pragma once
2 
3 #include <iostream>
4 #include <samchon/library/TSQLi.hpp>
5 
6 using namespace std;
7 using namespace samchon::library;
8 
9 namespace samchon
10 {
11 namespace examples
12 {
13 namespace sql
14 {
15  void main()
16  {
17  using namespace std;
18  using namespace samchon::library;
19 
20  shared_ptr<SQLi> sqli(new TSQLi());
21 
22  try
23  {
24  sqli->connect("211.239.161.211", "REDPRINTING_TEST", "redprinting_test", "redprinting");
25 
26  auto stmt = sqli->createStatement();
27  size_t uid = 5;
28  wstring name = L"고길동";
29  wstring department = L"홍보부; stmt->prepare(L"INSERT INTO 한글테이블 (번호, 이름, 부서) VALUES (?, ?, ?)", uid, name, department); stmt->execute(); stmt->executeDirectly(u8"SELECT * FROM 한글테이블"); while (stmt->fetch()) { int uid = stmt->at<int>(0); const string &name = stmt->at<string>(1); const string &department = stmt->at<string>(2); cout << uid << endl; cout << name << endl; cout << department << endl; } } catch (exception &e) { cout << e.what() << endl; } }; } } }";
30 
31  stmt->prepare(L"INSERT INTO 한글테이블 (번호, 이름, 부서) VALUES (?, ?, ?)", uid, name, department);
32  stmt->execute();
33 
34  stmt->executeDirectly(u8"SELECT * FROM 한글테이블); while (stmt->fetch()) { int uid = stmt->at<int>(0); const string &name = stmt->at<string>(1); const string &department = stmt->at<string>(2); cout << uid << endl; cout << name << endl; cout << department << endl; } } catch (exception &e) { cout << e.what() << endl; } }; } } }");
35 
36  while (stmt->fetch())
37  {
38  int uid = stmt->at<int>(0);
39  const string &name = stmt->at<string>(1);
40  const string &department = stmt->at<string>(2);
41 
42  cout << uid << endl;
43  cout << name << endl;
44  cout << department << endl;
45  }
46  }
47  catch (exception &e)
48  {
49  cout << e.what() << endl;
50  }
51  };
52 }
53 }
54 }
A SQL interface for T-SQL.
Definition: TSQLi.hpp:19