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 1064 게시물 읽기
No. 1064
Re: 흑흑흑~~~또 에러가.......
작성자
정재익
작성일
2000-05-22 07:39
조회수
16,348

답변이 늦어 죄송합니다.

 

현재 소스로 봐서는 크게 이상이 없습니다.

에러가 나는 곳은 일단 cursor 선언부에서 에러가 나는것 같군요.

만약 아직도 해결하지 못했다면, 디비 소스를 내게 메일로 보내 주세요.

테이블 구조를 모르다 보니 제대로 테스트가 안되고 있습니다.

그리고 일단 cursor 를 안 쓰는 방향으로 바꾸어 보시기 바랍니다.

즉 sqlstr = "select * from lotto where name='즉석복권'" 이런식으로 해서 사용해 보라는 것입니다.

 

그리고 일전에 만나서 얘기한 PHP script 를 CGI 롤 사용하는 방식에 대해서도 충분히 고려해 보시기 바랍니다. 만약 큰 부하가 안걸리는 일이라면 그것이 훨씬 더 좋은 방법일 것 같습니다. 소스가 간단해 지고, 컴파일이 필요없고, 필요할 경우 소스를 웹에서 바로 이용할 수도 있는 장점이 있습니다.

 

> 소스구요....

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

>

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

> e 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
15803
1065Data Type TEXT 에 대한 질문
이민우
2000-05-22
17284
1067┕>Re: Data Type TEXT 에 대한 질문
정재익
2000-05-22 14:41:44
17571
1069 ┕>Re: Re: Data Type TEXT 에 대한 질문
이민우
2000-05-22 15:52:34
17007
1061postgres 의 src디렉토리는 ....[초보]
조용호
2000-05-20
17209
1062┕>Re: postgres 의 src디렉토리는 ....[초보]
Coral
2000-05-20 15:01:01
17194
1063 ┕>Re: Re: postgres 의 src디렉토리는 ....[초보]
정재익
2000-05-22 06:15:53
17110
1060흑흑흑~~~또 에러가.......
김종혁
2000-05-19
15407
1064┕>Re: 흑흑흑~~~또 에러가.......
정재익
2000-05-22 07:39:54
16348
1070 ┕>Re: Re: 흑흑흑~~~또 에러가.......
김종혁
2000-05-22 22:36:28
15757
1071  ┕>Re: Re: Re: 흑흑흑~~~또 에러가.......
정재익
2000-05-23 03:02:46
15967
1100┕>Re: 흑흑흑~~~또 에러가.......
정재익
2000-05-25 03:07:03
15401
1058이런 에러가!!!!!!
김종혁
2000-05-19
15886
1059┕>Re: 이런 에러가!!!!!!
정재익
2000-05-19 09:26:36
17066
1056밑의 질문 다시요..
이채은
2000-05-18
16380
1057┕>Re: 밑의 질문 다시요..
Coral
2000-05-18 22:31:28
16960
1052pg_*** 수정하려면?
이채은
2000-05-18
14547
1055┕>Re: pg_*** 수정하려면?
정재익
2000-05-18 19:46:06
15033
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.020초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다