分类: 数据库开发技术
2015-03-15 10:17:02
/***************************************************************
* *
* Copyright (c) 2001-2014 McObject LLC. All Rights Reserved. *
* *
****************************************************************/
#include
#include
#include "sqlcln.h"
#include "rsqldb.h"
char sample_descr[] =
"Sample 'rsql_client' demonstrates the client-side implementation in a\n"
"client-server application.\n";
const char * db_name = "testdb";
const int SERVER_PORT = 5023;
char const* SERVER_HOST = "192.168.1.156";
const size_t MAX_LINE_LENGTH = 2048;
#define TaskNum 10
#define RecordNUM 10000000
// Define global SQL engine
using namespace McoSql;
static sample_task_t tasks[TaskNum];
typedef struct Param
{
int base;
int num;
MCO_RET rc;
}Param;
RemoteSqlEngine engine;
void task_insert(sample_task_t * descriptor)
{
int i, rc;
bool ret;
Param *t = (Param *)(descriptor->param);
RemoteSqlEngine engine;
ret = engine.open(SERVER_HOST, SERVER_PORT);
if (!ret) {
printf("Can't open server\n");
t->rc = MCO_E_ACCESS;
return;
}
int last = t->base + t->num;
for (i = t->base; i < last; i++)
{
try
{
rc = engine.executeStatement("insert into Tblrtuinfyx(id,rtukey,yxdh,value,vaild) values(%i,%i,%i,'abc','123')", i, i, i);
if (SQL_OK == rc || NO_MORE_ELEMENTS == rc) {
// printf("success->i == %d\n", i);
}
else {
t->rc = MCO_E_CORE;
engine.close();
return;
}
}
catch (McoSqlException err) {
t->rc = (MCO_RET)err.code;
engine.close();
return;
}
}
engine.close();
}
int main(int argc, char ** argv)
{
int i = 1;
time_t start_time;
Param Task_p[TaskNum];
char statement[MAX_LINE_LENGTH + 1];
char name[64];
sample_os_initialize(DEFAULT);
sample_header(sample_descr);
mco_runtime_start();
engine.open(SERVER_HOST, SERVER_PORT);
for (i = 0; i < TaskNum; i++)
{
Task_p[i].num = RecordNUM / TaskNum;
Task_p[i].base = (RecordNUM / TaskNum) * i;
Task_p[i].rc = MCO_S_OK;
}
start_time = sample_msec();
for (i = 0; i < TaskNum;i++)
{
sample_start_connected_task(&tasks[i], task_insert, 0, &Task_p[i]);
}
for (i = 0; i < TaskNum; i++)
{
sample_join_task(&tasks[i]);
}
for (i = 0; i < TaskNum; i++)
{
printf("Return code of task 1 %d(%s)\n", Task_p[i].rc, mco_strerror(Task_p[i].rc));
}
printf("\n\t%d objects: %d milliseconds,(%d microsecs/object)\n", RecordNUM,
(int)(sample_msec() - start_time), (int)(((sample_msec() - start_time) * 1000) / RecordNUM));
getchar();
// engine.close();
mco_runtime_stop();
sample_os_shutdown();
return 0;
}