Header And Logo

PostgreSQL
| The world's most advanced open source database.

pgtypeslib-num_test.c

Go to the documentation of this file.
00001 /* Processed by ecpg (regression mode) */
00002 /* These include files are added by the preprocessor */
00003 #include <ecpglib.h>
00004 #include <ecpgerrno.h>
00005 #include <sqlca.h>
00006 /* End of automatic include section */
00007 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
00008 
00009 #line 1 "num_test.pgc"
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <pgtypes_numeric.h>
00013 #include <decimal.h>
00014 
00015 
00016 #line 1 "regression.h"
00017 
00018 
00019 
00020 
00021 
00022 
00023 #line 6 "num_test.pgc"
00024 
00025 
00026 
00027 /*
00028 
00029 NOTE: This file has a different expect file for regression tests on MinGW32
00030 
00031 */
00032 
00033 
00034 int
00035 main(void)
00036 {
00037     char *text="error\n";
00038     numeric *value1, *value2, *res;
00039     /* exec sql begin declare section */
00040          
00041         /* = {0, 0, 0, 0, 0, NULL, NULL} ; */
00042     
00043 #line 22 "num_test.pgc"
00044  numeric * des ;
00045 /* exec sql end declare section */
00046 #line 24 "num_test.pgc"
00047 
00048     double d;
00049     long l1, l2;
00050     int i;
00051 
00052     ECPGdebug(1, stderr);
00053     /* exec sql whenever sqlerror  do sqlprint ( ) ; */
00054 #line 30 "num_test.pgc"
00055 
00056 
00057     { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); 
00058 #line 32 "num_test.pgc"
00059 
00060 if (sqlca.sqlcode < 0) sqlprint ( );}
00061 #line 32 "num_test.pgc"
00062 
00063 
00064     { ECPGsetcommit(__LINE__, "off", NULL);
00065 #line 34 "num_test.pgc"
00066 
00067 if (sqlca.sqlcode < 0) sqlprint ( );}
00068 #line 34 "num_test.pgc"
00069 
00070     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test ( text char ( 5 ) , num numeric ( 14 , 7 ) )", ECPGt_EOIT, ECPGt_EORT);
00071 #line 35 "num_test.pgc"
00072 
00073 if (sqlca.sqlcode < 0) sqlprint ( );}
00074 #line 35 "num_test.pgc"
00075 
00076 
00077     value1 = PGTYPESnumeric_new();
00078     PGTYPESnumeric_from_int(1407, value1);
00079     text = PGTYPESnumeric_to_asc(value1, -1);
00080     printf("from int = %s\n", text);
00081     free(text);
00082     PGTYPESnumeric_free(value1);
00083 
00084     value1 = PGTYPESnumeric_from_asc("2369.7", NULL);
00085     value2 = PGTYPESnumeric_from_asc("10.0", NULL);
00086     res = PGTYPESnumeric_new();
00087     PGTYPESnumeric_add(value1, value2, res);
00088     text = PGTYPESnumeric_to_asc(res, -1);
00089     printf("add = %s\n", text);
00090     free(text);
00091 
00092     PGTYPESnumeric_sub(res, value2, res);
00093     text = PGTYPESnumeric_to_asc(res, -1);
00094     printf("sub = %s\n", text);
00095     free(text);
00096     PGTYPESnumeric_free(value2);
00097 
00098     des = PGTYPESnumeric_new();
00099     PGTYPESnumeric_copy(res, des);
00100     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test ( text , num ) values ( 'test' , $1  )", 
00101     ECPGt_numeric,&(des),(long)1,(long)0,sizeof(numeric), 
00102     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
00103 #line 60 "num_test.pgc"
00104 
00105 if (sqlca.sqlcode < 0) sqlprint ( );}
00106 #line 60 "num_test.pgc"
00107 
00108 
00109     value2 = PGTYPESnumeric_from_asc("2369.7", NULL);
00110     PGTYPESnumeric_mul(value1, value2, res);
00111     PGTYPESnumeric_free(value2);
00112 
00113     { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select num from test where text = 'test'", ECPGt_EOIT, 
00114     ECPGt_numeric,&(des),(long)1,(long)0,sizeof(numeric), 
00115     ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
00116 #line 66 "num_test.pgc"
00117 
00118 if (sqlca.sqlcode < 0) sqlprint ( );}
00119 #line 66 "num_test.pgc"
00120 
00121 
00122     PGTYPESnumeric_mul(res, des, res);
00123     text = PGTYPESnumeric_to_asc(res, -1);
00124     printf("mul = %s\n", text);
00125     free(text);
00126     PGTYPESnumeric_free(des);
00127 
00128     value2 = PGTYPESnumeric_from_asc("10000", NULL);
00129     PGTYPESnumeric_div(res, value2, res);
00130     text = PGTYPESnumeric_to_asc(res, -1);
00131     PGTYPESnumeric_to_double(res, &d);
00132     printf("div = %s %e\n", text, d);
00133 
00134     PGTYPESnumeric_free(value1);
00135     PGTYPESnumeric_free(value2);
00136 
00137     value1 = PGTYPESnumeric_from_asc("2E7", NULL);
00138     value2 = PGTYPESnumeric_from_asc("14", NULL);
00139     i = PGTYPESnumeric_to_long(value1, &l1) | PGTYPESnumeric_to_long(value2, &l2);
00140     printf("to long(%d) = %ld %ld\n", i, l1, l2);
00141 
00142     free(text);
00143     PGTYPESnumeric_free(value1);
00144     PGTYPESnumeric_free(value2);
00145     PGTYPESnumeric_free(res);
00146 
00147     { ECPGtrans(__LINE__, NULL, "rollback");
00148 #line 93 "num_test.pgc"
00149 
00150 if (sqlca.sqlcode < 0) sqlprint ( );}
00151 #line 93 "num_test.pgc"
00152 
00153     { ECPGdisconnect(__LINE__, "CURRENT");
00154 #line 94 "num_test.pgc"
00155 
00156 if (sqlca.sqlcode < 0) sqlprint ( );}
00157 #line 94 "num_test.pgc"
00158 
00159 
00160     return (0);
00161 }