-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhello.cpp
More file actions
88 lines (72 loc) · 2.09 KB
/
hello.cpp
File metadata and controls
88 lines (72 loc) · 2.09 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include "./lib/ibpp/core/ibpp.h"
#include <iconv.h>
#include "include/json.hpp"
using jsoncons::null_type;
using jsoncons::json;
using namespace std;
std::string iconv_recode(std::string from, std::string to, std::string text);
int main()
{
std::string ServerName = "localhost";
std::string DbName = "MYDB";
std::string UserName = "SYSDBA";
std::string Password = "7ea9f10f";
std::string Role = "ADMIN";
std::string Charset = "WIN1251";
std::string Params = "";
IBPP::Database db1;
db1 = IBPP::DatabaseFactory(ServerName, DbName, UserName, Password, Role, Charset, Params);
std::cout<<"Trying to connect...\r\n";
db1->Connect();
IBPP::Transaction tr1 = IBPP::TransactionFactory(db1,
IBPP::amRead, IBPP::ilConcurrency, IBPP::lrWait);
tr1->Start();
std::cout<<"Connected. Now disconnecting...\r\n";
IBPP::Statement st1 = IBPP::StatementFactory(db1, tr1);
st1->Execute("SELECT MEM_ID, MEM_NAME FROM LINE");
json articles;
while(st1->Fetch())
{
std::string mem_name;
int mem_id;
st1->Get(1, &mem_id);
st1->Get(2, mem_name);
//std::cout<<mem_id<<'\t'<<iconv_recode("CP1251", "UTF-8", mem_name)<<std::endl;
articles[iconv_recode("CP1251", "UTF-8", mem_name)] = mem_id;
}
std::cout<<pretty_print(articles);
tr1->CommitRetain();
db1->Disconnect();
std::cout<<"Passed!\r\n";
return 0;
}
std::string iconv_recode(std::string from, std::string to, std::string text)
{
iconv_t cnv = iconv_open(to.c_str(), from.c_str());
if (cnv == (iconv_t) - 1)
{
iconv_close(cnv);
return "";
}
char *outbuf;
if ((outbuf = (char *) malloc(text.length()*2 + 1)) == NULL)
{
iconv_close(cnv);
return "";
}
char *ip = (char *) text.c_str(), *op = outbuf;
size_t icount = text.length(), ocount = text.length()*2;
if (iconv(cnv, &ip, &icount, &op, &ocount) != (size_t) - 1)
{
outbuf[text.length()*2 - ocount] = '\0';
text = outbuf;
}
else
{
text = "";
}
free(outbuf);
iconv_close(cnv);
return text;
}