//プロジェクト名postgres001 C++ソースファイルpostgres001.cpp libpq.lib #include #include #pragma comment(lib, "libpq.lib") extern "C" { __declspec(dllexport) long sqlopen(char * string01,char * string02,char * string03,char * string04); __declspec(dllexport) long sqlquery(long hsql,char * string01); __declspec(dllexport) char * sqlresult(long result,int row,char * delimiter,char * buf01); __declspec(dllexport) void sqlresclose(long result); __declspec(dllexport) void sqlclose(long hsql); __declspec(dllexport) char * shift_to_utf(char * string01,char * string02); __declspec(dllexport) char * utf_to_shift(char * string01,char * string02); long sqlopen(char * string01,char * string02,char * string03,char * string04) { PGconn * hsql; hsql=PQsetdbLogin(string01,NULL,NULL,NULL,string04,string02,string03); return (long)hsql; } long sqlquery(long hsql,char * string01) { PGresult * result; result=PQexec((PGconn *)hsql,string01); if ((PQresultStatus(result) == PGRES_COMMAND_OK) || (PQresultStatus(result) == PGRES_TUPLES_OK)) return (long)result; else return 0; } char * sqlresult(long result,int row,char * delimiter,char * buf01) { unsigned int lenmax=(strlen(buf01)-2); * buf01='\0'; char * resrow; int j,resrowmax,rescolmax; resrowmax=PQntuples((PGresult *)result); if(row>=resrowmax) { return buf01; } rescolmax=PQnfields((PGresult *)result); for(j=0;j=n) { memcpy(string02,param2,n); } else { * string02='\0'; } } else { * string02='\0'; } free(param1); free(param2); return string02; } char * utf_to_shift(char * string01,char * string02) { char *param1,*param2; int len,n,done; done = FALSE; n = MultiByteToWideChar(CP_UTF8, 0, string01, -1, NULL, 0 ); if(n != 0) { param1 = (char *)calloc(1,n*2 + 2); if (param1 != NULL) { n = MultiByteToWideChar(CP_UTF8, 0, string01, -1, (LPWSTR)param1, n ); if(n != 0) { done = TRUE; } } } if (done) { done = FALSE; n = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)param1, -1, NULL, 0, NULL, NULL); if(n != 0) { param2 = (char *)calloc(1,n + 2); if (param2 != NULL) { n = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)param1, -1, param2, n, NULL, NULL); if(n != 0) { done = TRUE; } } } } if (done) { len=strlen(string02); if (len>=n) { memcpy(string02,param2,n); } else { * string02='\0'; } } else { * string02='\0'; } free(param1); free(param2); return string02; } }