次のコールバック関数があります。
// This is the callback function to display the select data in the table
static int callback(void *NotUsed, int argc, char **argv, char **szColName)
{
for(int i = 0; i < argc; i++)
{
std::cout << " = " << argv[i] << std::endl;
}
std::cout << "\n";
return 0;
}
// prepare our sql statements
const char *pSQL[6];
pSQL[0] = "SELECT * FROM User";
// execute sql
for(int i = 0; i < 1; i++)
{
rc = sqlite3_exec(db, pSQL[i], callback, 0, &szErrMsg);
if(rc != SQLITE_OK)
{
std::cout << "SQL Error: " << szErrMsg << std::endl;
sqlite3_free(szErrMsg);
break;
}
}
次の出力を生成します
1
mark
mark@email.com
98989898
mark
mark
ADMN
U
Where are you studying
SIM
0
2
ken
ken@email.com
92222898
ken
ken
ADMN
U
Where are you studying
SIM
0
3
joseph
joseph@email.com
92333718
joseph
joseph
ADMN
U
Where are you studying
SIM
0
4
ricky
ricky@email.com
81822801
ricky
ricky
ADMN
U
Where are you studying
SIM
0
5
ck
ck@email.com
94567828
ck
ck
ADMN
U
Where are you studying
SIM
0
垂直方向ではなく、水平方向にフォーマットする必要があります。
1 mark mark@email.com 98989898 mark mark ADMN U Where are you studying SIM 0
2 ken ken@email.com 92222898 ken ken ADMN U Where are you studying SIM 0
3 joseph joseph@email.com 92333718 joseph joseph ADMN U Where are you studying SIM 0
4 ricky ricky@email.com 81822801 ricky ricky ADMN U Where are you studying SIM 0
5 ck ck@email.com 94567828 ck ck ADMN U Where are you studying SIM 0
コールバック関数でこれを使用してみました:
1) std::cout << argv[i] << "\t";
2) std::cout << argv[i] << setw(15);
3) std::cout << setw(15) << argv[i];
しかし、それが私に与えたのは、正しくフォーマットされていない行だけです。
1 mark test@email.com 98989898 mark mark ADMN U Where are you studying SIM 0
2 ken ken@email.com 92222898 ken ken ADMN U Where are you studying SIM 0
3 joseph joseph@email.com 92333718 joseph joseph ADMN U Where are you studying SIM 0
4 ricky ricky@email.com 81822801 ricky ricky ADMN U Where are you studying SIM 0
5 ck ck@email.com 94567828 ck ck ADMN U Where are you studying SIM 0