소스구요....
에러나는 라인은 주석으로 처리된 부분입니다.....
#include "stdio.h"
#include "/usr/include/pgsql/libpq/fe.h"
#include "string.h"
int main()
{
char *pghost, *pgport, *pgoptions, *pgtty, *dbName;
PGconn *Connection;
PGresult *result;
int number_of_lotto;
int nTuples;
char sqlstr[200];
int i;
int level;
int lotto_number;
int t_lotto_number;
int l_point;
char temp[10];
char data1[20],data2[20],data3[20];
char *LOTTO_NAME="즉석복권";
pgoptions=NULL;
pgtty=NULL;
dbName="lotto";
pghost="localhost";
pgport="5432";
Connection=PQsetdb(pghost,pgport,pgoptions,pgtty,dbName);
if(PQstatus(Connection)==CONNECTION_BAD)
{
fprintf(stdout,"connection_to_database_%s_failed\n\n",dbName);
PQfinish(Connection);
exit(1);
}
strcpy(sqlstr,"declare dcursor cursor for select * from lotto where name='")
;
strcat(sqlstr,LOTTO_NAME);
strcat(sqlstr,"' ");
result=PQexec(Connection,"BEGIN");
PQclear(result);
result=PQexec(Connection,sqlstr);
PQclear(result);
result=PQexec(Connection,"FETCH forward 10 in dcursor");
strcpy(temp,PQgetvalue(result,0,1));
number_of_lotto=atoi(temp);
result=PQexec(Connection,"END;");
PQclear(result);
strcpy(sqlstr,"update lotto set number_of_lotto_usable=");
strcat(sqlstr,temp);
strcat(sqlstr," where name='");
strcat(sqlstr,LOTTO_NAME);
strcat(sqlstr,"' ;");
result=PQexec(Connection,sqlstr);
if(PQresultStatus(result)!=PGRES_COMMAND_OK)
{
fprintf(stdout,"command failed \n\n");
fprintf(stdout,"%s",PQerrorMessage(Connection));
PQclear(result);
exit(1);
}
strcpy(sqlstr,"delete from level where lotto_name='");
strcat(sqlstr,LOTTO_NAME);
strcat(sqlstr,"'; ");
result=PQexec(Connection,sqlstr);
if(PQresultStatus(result)!=PGRES_COMMAND_OK)
{
fprintf(stdout,"command failed \n\n");
fprintf(stdout,"delete error : %s",PQerrorMessage(Connection));
PQclear(result);
exit(1);
}
PQclear(result);
// 이 아래 부분에서 에러가 납니다.....단순한 select문인데요......
이유를 알수 없네요.....
strcpy(sqlstr,"declare ecursor cursor for select * from leveldata where lotto_name='");
strcat(sqlstr,LOTTO_NAME);
strcat(sqlstr,"' ");
result=PQexec(Connection,"BEGIN");
PQclear(result);
result=PQexec(Connection,sqlstr);
PQclear(result);
result=PQexec(Connection,"FETCH forward 50 in ecursor");
if(PQresultStatus(result)!=PGRES_COMMAND_OK)
{
fprintf(stdout,"command failed \n\n"); //출력되는 에러 메시지임다~~
fprintf(stdout,"fetch error : %s",PQerrorMessage(Connection));
PQclear(result);
exit(1);
}
nTuples=PQntuples(result);
for(i=0;i<number_of_lotto&&i<nTuples;i++)
{
strcpy(data1,PQgetvalue(result,i,1));
strcpy(data2,PQgetvalue(result,i,2));
strcpy(data3,PQgetvalue(result,i,3));
strcpy(sqlstr,"insert into level values ('");
strcat(sqlstr,LOTTO_NAME);
strcat(sqlstr,"',");
strcat(sqlstr,data1);
strcat(sqlstr,",");
strcat(sqlstr,data2);
strcat(sqlstr,",");
strcat(sqlstr,data2);
strcat(sqlstr,",");
strcat(sqlstr,data3);
strcat(sqlstr,");");
PQexec(Connection,sqlstr);
}
result=PQexec(Connection,"END;");
if(PQresultStatus(result)!=PGRES_COMMAND_OK)
{
fprintf(stdout,"command failed \n\n");
fprintf(stdout,"end error : %s",PQerrorMessage(Connection));
PQclear(result);
exit(1);
}
PQclear(result);
PQfinish(Connection);
return 0;
}
|