database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
ㆍPostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
PostgreSQL Q&A 1060 게시물 읽기
No. 1060
흑흑흑~~~또 에러가.......
작성자
김종혁
작성일
2000-05-19 11:49
조회수
15,408

소스구요....

에러나는 라인은 주석으로 처리된 부분입니다.....

 

#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;

 

}

[Top]
No.
제목
작성자
작성일
조회
1066아파치 php3 , postgresql, oracle 을 연동 시키고 싶습니다.
초보자
2000-05-22
16762
1068┕>Re: 아파치 php3 , postgresql, oracle 을 연동 시키고 싶습니다.
정재익
2000-05-22 14:46:38
15804
1065Data Type TEXT 에 대한 질문
이민우
2000-05-22
17284
1067┕>Re: Data Type TEXT 에 대한 질문
정재익
2000-05-22 14:41:44
17574
1069 ┕>Re: Re: Data Type TEXT 에 대한 질문
이민우
2000-05-22 15:52:34
17007
1061postgres 의 src디렉토리는 ....[초보]
조용호
2000-05-20
17210
1062┕>Re: postgres 의 src디렉토리는 ....[초보]
Coral
2000-05-20 15:01:01
17196
1063 ┕>Re: Re: postgres 의 src디렉토리는 ....[초보]
정재익
2000-05-22 06:15:53
17113
1060흑흑흑~~~또 에러가.......
김종혁
2000-05-19
15408
1064┕>Re: 흑흑흑~~~또 에러가.......
정재익
2000-05-22 07:39:54
16349
1070 ┕>Re: Re: 흑흑흑~~~또 에러가.......
김종혁
2000-05-22 22:36:28
15759
1071  ┕>Re: Re: Re: 흑흑흑~~~또 에러가.......
정재익
2000-05-23 03:02:46
15969
1100┕>Re: 흑흑흑~~~또 에러가.......
정재익
2000-05-25 03:07:03
15404
1058이런 에러가!!!!!!
김종혁
2000-05-19
15887
1059┕>Re: 이런 에러가!!!!!!
정재익
2000-05-19 09:26:36
17069
1056밑의 질문 다시요..
이채은
2000-05-18
16381
1057┕>Re: 밑의 질문 다시요..
Coral
2000-05-18 22:31:28
16961
1052pg_*** 수정하려면?
이채은
2000-05-18
14550
1055┕>Re: pg_*** 수정하려면?
정재익
2000-05-18 19:46:06
15035
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.029초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다