mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-27 08:39:28 +08:00
141 lines
2.4 KiB
C
141 lines
2.4 KiB
C
|
/*
|
||
|
* insert.c
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
/*#define TEST_NON_NULLS*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <signal.h>
|
||
|
#include <time.h>
|
||
|
#include <libpq-fe.h>
|
||
|
#include "halt.h"
|
||
|
#include "pginterface.h"
|
||
|
|
||
|
int main(int argc, char **argv)
|
||
|
{
|
||
|
char query[4000];
|
||
|
int row =1;
|
||
|
int aint;
|
||
|
float afloat;
|
||
|
double adouble;
|
||
|
char achar[11], achar16[17], abpchar[11], avarchar[51], atext[51];
|
||
|
time_t aabstime;
|
||
|
int aint_null,
|
||
|
afloat_null,
|
||
|
adouble_null,
|
||
|
achar_null,
|
||
|
achar16_null,
|
||
|
abpchar_null,
|
||
|
avarchar_null,
|
||
|
atext_null,
|
||
|
aabstime_null;
|
||
|
|
||
|
if (argc != 2)
|
||
|
halt("Usage: %s database\n",argv[0]);
|
||
|
|
||
|
connectdb(argv[1],NULL,NULL,NULL,NULL);
|
||
|
|
||
|
on_error_continue();
|
||
|
doquery("DROP TABLE testfetch");
|
||
|
on_error_stop();
|
||
|
|
||
|
doquery("\
|
||
|
CREATE TABLE testfetch( \
|
||
|
aint int4, \
|
||
|
afloat float4, \
|
||
|
adouble float8, \
|
||
|
achar char, \
|
||
|
achar16 char16, \
|
||
|
abpchar char(10), \
|
||
|
avarchar varchar(50), \
|
||
|
atext text, \
|
||
|
aabstime abstime) \
|
||
|
");
|
||
|
|
||
|
#ifdef TEST_NON_NULLS
|
||
|
sprintf(query,"INSERT INTO testfetch VALUES ( \
|
||
|
0, \
|
||
|
0, \
|
||
|
0, \
|
||
|
'', \
|
||
|
'', \
|
||
|
'', \
|
||
|
'', \
|
||
|
'', \
|
||
|
'');");
|
||
|
#else
|
||
|
sprintf(query,"INSERT INTO testfetch VALUES ( \
|
||
|
NULL, \
|
||
|
NULL, \
|
||
|
NULL, \
|
||
|
NULL, \
|
||
|
NULL, \
|
||
|
NULL, \
|
||
|
NULL, \
|
||
|
NULL, \
|
||
|
NULL);");
|
||
|
#endif
|
||
|
doquery(query);
|
||
|
|
||
|
doquery("BEGIN WORK");
|
||
|
doquery("DECLARE c_testfetch BINARY CURSOR FOR \
|
||
|
SELECT * FROM testfetch");
|
||
|
|
||
|
doquery("FETCH ALL IN c_testfetch");
|
||
|
|
||
|
if (fetch(
|
||
|
&aint,
|
||
|
&afloat,
|
||
|
&adouble,
|
||
|
achar,
|
||
|
achar16,
|
||
|
abpchar,
|
||
|
avarchar,
|
||
|
atext,
|
||
|
&aabstime) != END_OF_TUPLES)
|
||
|
printf("int %d\nfloat %f\ndouble %f\nchar %s\nchar16 %s\n\
|
||
|
bpchar %s\nvarchar %s\ntext %s\nabstime %s\n",
|
||
|
aint,
|
||
|
afloat,
|
||
|
adouble,
|
||
|
achar,
|
||
|
achar16,
|
||
|
abpchar,
|
||
|
avarchar,
|
||
|
atext,
|
||
|
ctime(&aabstime));
|
||
|
if (fetchisnull(
|
||
|
&aint_null,
|
||
|
&afloat_null,
|
||
|
&adouble_null,
|
||
|
&achar_null,
|
||
|
&achar16_null,
|
||
|
&abpchar_null,
|
||
|
&avarchar_null,
|
||
|
&atext_null,
|
||
|
&aabstime_null) != END_OF_TUPLES)
|
||
|
printf("NULL:\nint %d\nfloat %d\ndouble %d\nchar %d\nchar16 %d\n\
|
||
|
bpchar %d\nvarchar %d\ntext %d\nabstime %d\n",
|
||
|
aint_null,
|
||
|
afloat_null,
|
||
|
adouble_null,
|
||
|
achar_null,
|
||
|
achar16_null,
|
||
|
abpchar_null,
|
||
|
avarchar_null,
|
||
|
atext_null,
|
||
|
aabstime_null);
|
||
|
|
||
|
|
||
|
doquery("CLOSE c_testfetch");
|
||
|
doquery("COMMIT WORK");
|
||
|
printf("--- 1 row inserted\n");
|
||
|
|
||
|
row++;
|
||
|
|
||
|
disconnectdb();
|
||
|
return 0;
|
||
|
}
|
||
|
|