Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
1c7fad57
Commit
1c7fad57
authored
Mar 03, 2000
by
Michael Meskes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*** empty log message ***
parent
3a81a1a4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
252 additions
and
68 deletions
+252
-68
src/interfaces/ecpg/test/Makefile
src/interfaces/ecpg/test/Makefile
+4
-3
src/interfaces/ecpg/test/dyntest.pgc
src/interfaces/ecpg/test/dyntest.pgc
+107
-65
src/interfaces/ecpg/test/dyntest2.pgc
src/interfaces/ecpg/test/dyntest2.pgc
+141
-0
No files found.
src/interfaces/ecpg/test/Makefile
View file @
1c7fad57
all
:
test1 test2 test3 test4 perftest dyntest
all
:
test1 test2 test3 test4 perftest dyntest
dyntest2
#LDFLAGS=-g -I /usr/local/pgsql/include -L/usr/local/pgsql/lib -lecpg -lpq -lcrypt
LDFLAGS
=
-g
-I
../include
-I
/usr/include/postgresql
-L
/usr/lib/postgresql
-L
../lib
-lecpg
-lpq
-lcrypt
LDFLAGS
=
-g
-I
../include
-I
/usr/include/postgresql
-L
../lib
-L
/usr/lib/postgresql
-lecpg
-lpq
-lcrypt
#LDFLAGS=-g -I/usr/include/postgresql -lecpg -lpq -lcrypt
#ECPG=/usr/local/pgsql/bin/ecpg
...
...
@@ -16,9 +16,10 @@ test3: test3.c
test4
:
test4.c
perftest
:
perftest.c
dyntest
:
dyntest.c
dyntest2
:
dyntest2.c
.pgc.c
:
$(ECPG)
$?
clean
:
-
/bin/rm test1 test2 test3 test4 perftest
*
.c log dyntest
-
/bin/rm test1 test2 test3 test4 perftest
*
.c log dyntest
dyntest2
src/interfaces/ecpg/test/dyntest.pgc
View file @
1c7fad57
...
...
@@ -2,7 +2,7 @@
*
* Copyright (c) 2000, Christof Petig <christof.petig@wtal.de>
*
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Attic/dyntest.pgc,v 1.
4 2000/02/23 19:26:04
meskes Exp $
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Attic/dyntest.pgc,v 1.
5 2000/03/03 13:24:06
meskes Exp $
*/
#include <stdio.h>
...
...
@@ -11,18 +11,17 @@ exec sql include sql3types;
exec sql include sqlca;
void error()
{
printf("\n#%d:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
{ printf("#%d:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
exit(1);
}
int main(int argc,char **argv)
{
exec sql begin declare section;
{ exec sql begin declare section;
int COUNT;
int INTVAR
, BOOLVAR
;
int INTVAR;
int INDEX;
int INDICATOR;
bool BOOLVAR;
int TYPE,LENGTH,OCTET_LENGTH,PRECISION,SCALE,NULLABLE,RETURNED_OCTET_LENGTH;
int DATETIME_INTERVAL_CODE;
char NAME[120];
...
...
@@ -30,22 +29,18 @@ exec sql begin declare section;
float FLOATVAR;
double DOUBLEVAR;
char QUERY[1024];
exec sql end declare section;
char DB[1024];
exec sql end declare section;
int done=0;
FILE *dbgs;
exec sql var BOOLVAR is bool;
if ((dbgs = fopen("log", "w")) != NULL)
ECPGdebug(1, dbgs);
snprintf(QUERY,sizeof QUERY,"select * from %s",argc>1?argv[1]:"pg_tables");
snprintf(QUERY,sizeof QUERY,"select * from %s",argc>1
&& argv[1][0]
?argv[1]:"pg_tables");
exec sql whenever sqlerror do error();
exec sql allocate descriptor MYDESC;
exec sql connect to mm;
strncpy(DB,argc>2?argv[2]:"mm",sizeof DB);
exec sql connect to :DB;
exec sql prepare MYQUERY from :QUERY;
exec sql declare MYCURS cursor for MYQUERY;
...
...
@@ -59,83 +54,130 @@ exec sql end declare section;
exec sql get descriptor MYDESC :COUNT = count;
if (!done)
{ printf("Count %d\n",COUNT);
{ printf("%d Columns\n",COUNT);
for (INDEX=1;INDEX<=COUNT;++INDEX)
{ exec sql get descriptor MYDESC value :INDEX
:TYPE = type,
:LENGTH = length, :OCTET_LENGTH=octet_length,
:PRECISION = precision, :SCALE=scale,
:NULLABLE=nullable, :NAME=name;
printf("%s ",NAME);
switch (TYPE)
{ case SQL3_BOOLEAN:
printf("bool ");
break;
case SQL3_NUMERIC:
printf("numeric(%d,%d) ",PRECISION,SCALE);
break;
case SQL3_DECIMAL:
printf("decimal(%d,%d) ",PRECISION,SCALE);
break;
case SQL3_INTEGER:
printf("integer ");
break;
case SQL3_SMALLINT:
printf("smallint ");
break;
case SQL3_FLOAT:
printf("float(%d,%d) ",PRECISION,SCALE);
break;
case SQL3_REAL:
printf("real ");
break;
case SQL3_DOUBLE_PRECISION:
printf("double precision ");
break;
case SQL3_DATE_TIME_TIMESTAMP:
exec sql get descriptor MYDESC value :INDEX
:DATETIME_INTERVAL_CODE=datetime_interval_code;
switch(DATETIME_INTERVAL_CODE)
{ case SQL3_DDT_DATE:
printf("date "); break;
case SQL3_DDT_TIME:
printf("time "); break;
case SQL3_DDT_TIMESTAMP:
printf("timestamp "); break;
case SQL3_DDT_TIME_WITH_TIME_ZONE:
printf("time with time zone "); break;
case SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE:
printf("timestamp with time zone "); break;
}
break;
case SQL3_INTERVAL:
printf("interval ");
break;
case SQL3_CHARACTER:
if (LENGTH>0) printf("char(%d) ",LENGTH);
else printf("char(?) ");
break;
case SQL3_CHARACTER_VARYING:
if (LENGTH>0) printf("varchar(%d) ",LENGTH);
else printf("varchar() ");
break;
default:
if (TYPE<0) printf("<OID %d> ",-TYPE);
else printf("<SQL3 %d> ",TYPE);
break;
}
if (!NULLABLE) printf("not null ");
if (OCTET_LENGTH>0) printf("[%d bytes]",OCTET_LENGTH);
putchar('\n');
}
putchar('\n');
done=1;
}
for (INDEX=1;INDEX<=COUNT;++INDEX)
{ exec sql get descriptor MYDESC value :INDEX
:TYPE = type,
:LENGTH = length, :OCTET_LENGTH=octet_length,
:RETURNED_OCTET_LENGTH=returned_octet_length,
:PRECISION = precision, :SCALE=scale,
:NULLABLE=nullable, :NAME=name,
:TYPE = type, :SCALE=scale, :PRECISION = precision,
:INDICATOR=indicator;
printf("%2d\t%s (type: %d length: %d precision: %d scale: %d
\toctet_length: %d returned_octet_length: %d nullable: %d)\n\t= "
,INDEX,NAME,TYPE,LENGTH,PRECISION,SCALE
,OCTET_LENGTH,RETURNED_OCTET_LENGTH,NULLABLE);
if (INDICATOR==-1) printf("NULL\n");
if (INDICATOR==-1) printf("NULL");
else switch (TYPE)
{
case SQL3_BOOLEAN:
{ case SQL3_BOOLEAN:
exec sql get descriptor MYDESC value :INDEX :BOOLVAR=data;
printf("%s\n",BOOLVAR ?
"true":"false");
break;
case SQL3_NUMERIC:
case SQL3_DECIMAL:
if (SCALE==0)
printf(BOOLVAR?
"true":"false");
break;
case SQL3_NUMERIC:
case SQL3_DECIMAL:
if (SCALE==0)
// we might even print leading zeros "%0*d"
{ exec sql get descriptor MYDESC value :INDEX :INTVAR=data;
printf("%
d\n"
,INTVAR);
printf("%
*d",PRECISION
,INTVAR);
}
else
{ exec sql get descriptor MYDESC value :INDEX :FLOATVAR=data;
printf("%
.*f\n"
,SCALE,FLOATVAR);
printf("%
*.*f",PRECISION+1
,SCALE,FLOATVAR);
}
break;
case SQL3_INTEGER:
case SQL3_SMALLINT:
case SQL3_INTEGER:
case SQL3_SMALLINT:
exec sql get descriptor MYDESC value :INDEX :INTVAR=data;
printf("%d
\n
",INTVAR);
printf("%d",INTVAR);
break;
case SQL3_FLOAT:
case SQL3_REAL:
case SQL3_FLOAT:
case SQL3_REAL:
exec sql get descriptor MYDESC value :INDEX :FLOATVAR=data;
printf("%
.*f\n",PRECISION
,FLOATVAR);
printf("%
f"
,FLOATVAR);
break;
case SQL3_DOUBLE_PRECISION:
case SQL3_DOUBLE_PRECISION:
exec sql get descriptor MYDESC value :INDEX :DOUBLEVAR=data;
printf("%.*f\n",PRECISION,DOUBLEVAR);
break;
case SQL3_DATE_TIME_TIMESTAMP:
exec sql get descriptor MYDESC value :INDEX
:DATETIME_INTERVAL_CODE=datetime_interval_code,
:STRINGVAR=data;
printf("%d \"%s\"\n",DATETIME_INTERVAL_CODE,STRINGVAR);
printf("%f",DOUBLEVAR);
break;
case SQL3_INTERVAL:
case SQL3_DATE_TIME_TIMESTAMP:
case SQL3_INTERVAL:
case SQL3_CHARACTER:
case SQL3_CHARACTER_VARYING:
default:
exec sql get descriptor MYDESC value :INDEX :STRINGVAR=data;
printf("\"%s\"\n",STRINGVAR);
break;
case SQL3_CHARACTER:
case SQL3_CHARACTER_VARYING:
exec sql get descriptor MYDESC value :INDEX :STRINGVAR=data;
printf("\"%s\"\n",STRINGVAR);
break;
default:
exec sql get descriptor MYDESC value :INDEX :STRINGVAR=data;
printf("<\"%s\">\n",STRINGVAR);
printf("'%s'",STRINGVAR);
break;
}
putchar('|');
}
putchar('\n');
}
exec sql close MYCURS;
exec sql deallocate descriptor MYDESC;
if (dbgs != NULL)
fclose(dbgs);
return 0;
}
src/interfaces/ecpg/test/dyntest2.pgc
0 → 100644
View file @
1c7fad57
/* dynamic SQL test program
*
* Copyright (c) 2000, Christof Petig <christof.petig@wtal.de>
*
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/test/Attic/dyntest2.pgc,v 1.1 2000/03/03 13:24:06 meskes Exp $
*/
#include <stdio.h>
exec sql include sql3types;
exec sql include sqlca;
void error()
{
printf("\n#%d:%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
exit(1);
}
int main(int argc,char **argv)
{
exec sql begin declare section;
int COUNT;
int INTVAR, BOOLVAR;
int INDEX;
int INDICATOR;
int TYPE,LENGTH,OCTET_LENGTH,PRECISION,SCALE,NULLABLE,RETURNED_OCTET_LENGTH;
int DATETIME_INTERVAL_CODE;
char NAME[120];
char STRINGVAR[1024];
float FLOATVAR;
double DOUBLEVAR;
char QUERY[1024];
exec sql end declare section;
int done=0;
FILE *dbgs;
exec sql var BOOLVAR is bool;
if ((dbgs = fopen("log", "w")) != NULL)
ECPGdebug(1, dbgs);
snprintf(QUERY,sizeof QUERY,"select * from %s",argc>1?argv[1]:"pg_tables");
exec sql whenever sqlerror do error();
exec sql allocate descriptor MYDESC;
exec sql connect to mm;
exec sql prepare MYQUERY from :QUERY;
exec sql declare MYCURS cursor for MYQUERY;
exec sql open MYCURS;
while (1)
{ exec sql fetch in MYCURS into sql descriptor MYDESC;
if (sqlca.sqlcode) break;
exec sql get descriptor MYDESC :COUNT = count;
if (!done)
{ printf("Count %d\n",COUNT);
done=1;
}
for (INDEX=1;INDEX<=COUNT;++INDEX)
{ exec sql get descriptor MYDESC value :INDEX
:TYPE = type,
:LENGTH = length, :OCTET_LENGTH=octet_length,
:RETURNED_OCTET_LENGTH=returned_octet_length,
:PRECISION = precision, :SCALE=scale,
:NULLABLE=nullable, :NAME=name,
:INDICATOR=indicator;
printf("%2d\t%s (type: %d length: %d precision: %d scale: %d
\toctet_length: %d returned_octet_length: %d nullable: %d)\n\t= "
,INDEX,NAME,TYPE,LENGTH,PRECISION,SCALE
,OCTET_LENGTH,RETURNED_OCTET_LENGTH,NULLABLE);
if (INDICATOR==-1) printf("NULL\n");
else switch (TYPE)
{
case SQL3_BOOLEAN:
exec sql get descriptor MYDESC value :INDEX :BOOLVAR=data;
printf("%s\n",BOOLVAR ? "true":"false");
break;
case SQL3_NUMERIC:
case SQL3_DECIMAL:
if (SCALE==0)
{ exec sql get descriptor MYDESC value :INDEX :INTVAR=data;
printf("%d\n",INTVAR);
}
else
{ exec sql get descriptor MYDESC value :INDEX :FLOATVAR=data;
printf("%.*f\n",SCALE,FLOATVAR);
}
break;
case SQL3_INTEGER:
case SQL3_SMALLINT:
exec sql get descriptor MYDESC value :INDEX :INTVAR=data;
printf("%d\n",INTVAR);
break;
case SQL3_FLOAT:
case SQL3_REAL:
exec sql get descriptor MYDESC value :INDEX :FLOATVAR=data;
printf("%.*f\n",PRECISION,FLOATVAR);
break;
case SQL3_DOUBLE_PRECISION:
exec sql get descriptor MYDESC value :INDEX :DOUBLEVAR=data;
printf("%.*f\n",PRECISION,DOUBLEVAR);
break;
case SQL3_DATE_TIME_TIMESTAMP:
exec sql get descriptor MYDESC value :INDEX
:DATETIME_INTERVAL_CODE=datetime_interval_code,
:STRINGVAR=data;
printf("%d \"%s\"\n",DATETIME_INTERVAL_CODE,STRINGVAR);
break;
case SQL3_INTERVAL:
exec sql get descriptor MYDESC value :INDEX :STRINGVAR=data;
printf("\"%s\"\n",STRINGVAR);
break;
case SQL3_CHARACTER:
case SQL3_CHARACTER_VARYING:
exec sql get descriptor MYDESC value :INDEX :STRINGVAR=data;
printf("\"%s\"\n",STRINGVAR);
break;
default:
exec sql get descriptor MYDESC value :INDEX :STRINGVAR=data;
printf("<\"%s\">\n",STRINGVAR);
break;
}
}
}
exec sql close MYCURS;
exec sql deallocate descriptor MYDESC;
if (dbgs != NULL)
fclose(dbgs);
return 0;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment