pgnulltest.c
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:3k
- /*
- * pgnulltest.c
- *
- */
- #define TEST_NON_NULLS
- #include <stdio.h>
- #include <time.h>
- #include <halt.h>
- #include <libpq-fe.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 databasen", 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 (fetchwithnulls(
- &aint,
- &aint_null,
- &afloat,
- &afloat_null,
- &adouble,
- &adouble_null,
- achar,
- &achar_null,
- achar16,
- &achar16_null,
- abpchar,
- &abpchar_null,
- avarchar,
- &avarchar_null,
- atext,
- &atext_null,
- &aabstime,
- &aabstime_null) != END_OF_TUPLES)
- printf("int %dnfloat %fndouble %fnchar %snchar16 %sn
- bpchar %snvarchar %sntext %snabstime %sn",
- aint,
- afloat,
- adouble,
- achar,
- achar16,
- abpchar,
- avarchar,
- atext,
- ctime(&aabstime));
- printf("NULL:nint %dnfloat %dndouble %dnchar %dnchar16 %dn
- bpchar %dnvarchar %dntext %dnabstime %dn",
- 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("--- %-d rows inserted so farn", row);
- row++;
- disconnectdb();
- return 0;
- }