이 문서는 지원되지 않는 버전의 토토 핫을위한 것입니다.
당신은에 대해 같은 페이지를 볼 수 있습니다
현재버전 또는 위에 나열된 다른 지원 버전 중 하나입니다.
/*-------------------------------------------------------------------
*
* testlo.c--
* LIBPQ로 큰 물체를 사용하여 테스트하십시오
*
* 저작권 (C) 1994, 캘리포니아 대학교 리전트
*
*
* 식별
* /usr/local/devel/pglite/cvs/src/doc/manual.me,v 1.16 1995/09/01 23:55:00 Jolly Exp
*
*------------------------------------------------------------------------
*/
#include <stdio.h
#include "libpq-fe.h"
#include "libpq/libpq-fs.h"
#define bufsize 1024
/*
* importFile * "in_filename"import 파일 "in_filename"은 큰 개체 "lobjoid"로 데이터베이스로 가져옵니다.
*
*/
OID importFile (pg토토 핫 *토토 핫, char *filename)
Oid lobjid;
int lobj_fd;
char buf [bufsize];
int nbytes, tmp;
int fd;
/*
* 읽을 파일을 엽니 다
*/
fd = Open (filename, o_rdonly, 0666);
if (fd <0) / * error * /
fprintf (stderr, "유닉스 파일을 열 수 없습니다
/*
* 큰 물체를 만듭니다
*/
lobjid = lo_creat (토토 핫, inv_read | inv_write);
if (lobjid == 0)
fprintf (Stderr, "큰 객체를 만들 수 없음");
lobj_fd = lo_open (토토 핫, lobjid, inv_write);
/*
* Unix 파일에서 읽고 반전 파일에 쓰기
*/
while ((nbytes = read (fd, buf, bufsize)) 0)
tmp = lo_write (토토 핫, lobj_fd, buf, nbytes);
if (tmp <nbytes)
fprintf (stderr,”읽는 동안 오류
(void) 닫기 (fd);
(void) lo_close (토토 핫, lobj_fd);
리턴 로지드;
void pickout (pg토토 핫 *토토 핫, oid lobjid, int start, int len)
int lobj_fd;
char* buf;
int nbytes;
int nread;
lobj_fd = lo_open (토토 핫, lobjid, inv_read);
if (lobj_fd <0)
fprintf (stderr, "큰 물체 %d를 열 수 없음",
lobjid);
lo_lseek (토토 핫, lobj_fd, start, seek_set);
buf = malloc (len+1);
nread = 0;
while (len -nread 0)
nbytes = lo_read (토토 핫, lobj_fd, buf, len -nread);
buf [nbytes] = '';
fprintf (stderr, " %s", buf);
nread += nbytes;
fprintf (stderr, "0);
lo_close (토토 핫, lobj_fd);
void -crufrite (pg토토 핫 *토토 핫, oid lobjid, int start, int len)
int lobj_fd;
char* buf;
int nbytes;
int nwritten;
int i;
lobj_fd = lo_open (토토 핫, lobjid, inv_read);
if (lobj_fd <0)
fprintf (stderr, "큰 물체 %d를 열 수 없음",
lobjid);
lo_lseek (토토 핫, lobj_fd, start, seek_set);
buf = malloc (len+1);
for (i = 0; i <len; i ++)
buf [i] = 'x';
buf [i] = '';
nwrretten = 0;
while (len -nwritten 0)
nbytes = lo_write (토토 핫, lobj_fd, buf + nwritten, len -nwritten);
nwrretten += nbytes;
fprintf (stderr, "0);
lo_close (토토 핫, lobj_fd);
/*
* ExportFile * "out_filename"을 제출하려면 큰 개체 "lobjoid"를 내보내기
*
*/
void ExportFile (PG토토 핫 *토토 핫, OID LOBJID, char *filename)
int lobj_fd;
char buf [bufsize];
int nbytes, tmp;
int fd;
/*
* 반전 "객체"를 만듭니다.
*/
lobj_fd = lo_open (토토 핫, lobjid, inv_read);
if (lobj_fd <0)
fprintf (stderr, "큰 물체 %d를 열 수 없음",
lobjid);
/*
* 작성할 파일을 엽니 다
*/
fd = Open (filename, o_creat | o_wronly, 0666);
if (fd <0) / * error * /
fprintf (stderr, "유닉스 파일을 열 수 없습니다
filename);
/*
* Unix 파일에서 읽고 반전 파일에 쓰기
*/
while ((nbytes = lo_read (토토 핫, lobj_fd, buf, bufsize)) 0)
tmp = 쓰기 (fd, buf, nbytes);
if (tmp <nbytes)
fprintf (stderr,”쓰기 동안 오류
filename);
(void) lo_close (토토 핫, lobj_fd);
(void) 닫기 (fd);
반품;
무효의
exit_nicely (pg토토 핫* 토토 핫)
pqfinish (토토 핫);
출구 (1);
int
메인 (Int Argc, char ** argv)
char *in_filename, *out_filename;
char *데이터베이스;
Oid lobjoid;
pg토토 핫 *토토 핫;
pgresult *res;
if (argc! = 4)
fprintf (stderr, "usage : %s database_name in_filename out_filename0,
argv [0]);
출구 (1);
데이터베이스 = argv [1];
in_filename = argv [2];
out_filename = argv [3];
/*
* 연결을 설정하십시오
*/
토토 핫 = pqsetdb (null, null, null, null, database);
/ * 백엔드 연결이 성공적으로 만들어 졌는지 확인하십시오 */
if (pqstatus (토토 핫) == 토토 핫ection_bad)
fprintf (stderr, "데이터베이스 '%s'에 대한 연결 실패 .0, 데이터베이스);
fprintf (stderr, "%s", pqerrormessage (토토 핫));
exit_nicely (토토 핫);
RES = PQEXEC (토토 핫, "시작");
PQCLEAR (RES);
printf ( "파일 가져 오기
/* lobjoid = importFile (토토 핫, in_filename); */
lobjoid = lo_import (토토 핫, in_filename);
/*
printf ( "큰 물체 %d.0, lobjoid);
printf ( "큰 대상의 1000-2000 바이트를 선택);
픽 아웃 (토토 핫, Lobjoid, 1000, 1000);
printf ( "x's0을 가진 큰 객체의 초과 작품 1000-2000);
덮어 쓰기 (토토 핫, Lobjoid, 1000, 1000);
*/
printf ( "큰 개체를 파일로 내보내는 것
/* ExportFile (토토 핫, lobjoid, out_filename); */
lo_export (토토 핫, lobjoid, out_filename);
res = pqexec (토토 핫, "end");
PQCLEAR (RES);
pqfinish (토토 핫);
출구 (0);
이전 |
홈 |
다음 |
큰 액세스
libpq의 개체 |
up |
ECPG- 내장 된 SQL
C에서 |