PageRenderTime 1290ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/src/interfaces/ecpg/test/expected/sql-indicators.c

https://gitlab.com/kush/jarulraj-postgresql-cpp
C | 189 lines | 108 code | 54 blank | 27 comment | 1 complexity | af249abce018b91e3d76612aa0e16855 MD5 | raw file
  1. /* Processed by ecpg (regression mode) */
  2. /* These include files are added by the preprocessor */
  3. #include <ecpglib.h>
  4. #include <ecpgerrno.h>
  5. #include <sqlca.h>
  6. /* End of automatic include section */
  7. #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
  8. #line 1 "indicators.pgc"
  9. #include <stdio.h>
  10. #line 1 "sqlca.h"
  11. #ifndef POSTGRES_SQLCA_H
  12. #define POSTGRES_SQLCA_H
  13. #ifndef PGDLLIMPORT
  14. #if defined(WIN32) || defined(__CYGWIN__)
  15. #define PGDLLIMPORT __declspec (dllimport)
  16. #else
  17. #define PGDLLIMPORT
  18. #endif /* __CYGWIN__ */
  19. #endif /* PGDLLIMPORT */
  20. #define SQLERRMC_LEN 150
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. struct sqlca_t
  26. {
  27. char sqlcaid[8];
  28. long sqlabc;
  29. long sqlcode;
  30. struct
  31. {
  32. int sqlerrml;
  33. char sqlerrmc[SQLERRMC_LEN];
  34. } sqlerrm;
  35. char sqlerrp[8];
  36. long sqlerrd[6];
  37. /* Element 0: empty */
  38. /* 1: OID of processed tuple if applicable */
  39. /* 2: number of rows processed */
  40. /* after an INSERT, UPDATE or */
  41. /* DELETE statement */
  42. /* 3: empty */
  43. /* 4: empty */
  44. /* 5: empty */
  45. char sqlwarn[8];
  46. /* Element 0: set to 'W' if at least one other is 'W' */
  47. /* 1: if 'W' at least one character string */
  48. /* value was truncated when it was */
  49. /* stored into a host variable. */
  50. /*
  51. * 2: if 'W' a (hopefully) non-fatal notice occurred
  52. */ /* 3: empty */
  53. /* 4: empty */
  54. /* 5: empty */
  55. /* 6: empty */
  56. /* 7: empty */
  57. char sqlstate[5];
  58. };
  59. struct sqlca_t *ECPGget_sqlca(void);
  60. #ifndef POSTGRES_ECPG_INTERNAL
  61. #define sqlca (*ECPGget_sqlca())
  62. #endif
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif
  67. #line 3 "indicators.pgc"
  68. #line 1 "regression.h"
  69. #line 4 "indicators.pgc"
  70. int main()
  71. {
  72. /* exec sql begin declare section */
  73. #line 9 "indicators.pgc"
  74. int intvar = 5 ;
  75. #line 10 "indicators.pgc"
  76. int nullind = - 1 ;
  77. /* exec sql end declare section */
  78. #line 11 "indicators.pgc"
  79. ECPGdebug(1,stderr);
  80. { ECPGconnect(__LINE__, 0, "regress1" , NULL, NULL , NULL, 0); }
  81. #line 15 "indicators.pgc"
  82. { ECPGsetcommit(__LINE__, "off", NULL);}
  83. #line 16 "indicators.pgc"
  84. { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table indicator_test ( \"id\" int primary key , \"str\" text not null , val int null )", ECPGt_EOIT, ECPGt_EORT);}
  85. #line 21 "indicators.pgc"
  86. { ECPGtrans(__LINE__, NULL, "commit work");}
  87. #line 22 "indicators.pgc"
  88. { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into indicator_test ( id , str , val ) values ( 1 , 'Hello' , 0 )", ECPGt_EOIT, ECPGt_EORT);}
  89. #line 24 "indicators.pgc"
  90. /* use indicator in insert */
  91. { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into indicator_test ( id , str , val ) values ( 2 , 'Hi there' , $1 )",
  92. ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
  93. ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EOIT, ECPGt_EORT);}
  94. #line 27 "indicators.pgc"
  95. nullind = 0;
  96. { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into indicator_test ( id , str , val ) values ( 3 , 'Good evening' , $1 )",
  97. ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
  98. ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EOIT, ECPGt_EORT);}
  99. #line 29 "indicators.pgc"
  100. { ECPGtrans(__LINE__, NULL, "commit work");}
  101. #line 30 "indicators.pgc"
  102. /* use indicators to get information about selects */
  103. { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 1", ECPGt_EOIT,
  104. ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
  105. ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
  106. #line 33 "indicators.pgc"
  107. { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 2", ECPGt_EOIT,
  108. ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
  109. ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EORT);}
  110. #line 34 "indicators.pgc"
  111. printf("intvar: %d, nullind: %d\n", intvar, nullind);
  112. { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 3", ECPGt_EOIT,
  113. ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
  114. ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EORT);}
  115. #line 36 "indicators.pgc"
  116. printf("intvar: %d, nullind: %d\n", intvar, nullind);
  117. /* use indicators for update */
  118. intvar = 5; nullind = -1;
  119. { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "update indicator_test set val = $1 where id = 1",
  120. ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
  121. ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EOIT, ECPGt_EORT);}
  122. #line 41 "indicators.pgc"
  123. { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select val from indicator_test where id = 1", ECPGt_EOIT,
  124. ECPGt_int,&(intvar),(long)1,(long)1,sizeof(int),
  125. ECPGt_int,&(nullind),(long)1,(long)1,sizeof(int), ECPGt_EORT);}
  126. #line 42 "indicators.pgc"
  127. printf("intvar: %d, nullind: %d\n", intvar, nullind);
  128. { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table indicator_test", ECPGt_EOIT, ECPGt_EORT);}
  129. #line 45 "indicators.pgc"
  130. { ECPGtrans(__LINE__, NULL, "commit work");}
  131. #line 46 "indicators.pgc"
  132. { ECPGdisconnect(__LINE__, "CURRENT");}
  133. #line 48 "indicators.pgc"
  134. return 0;
  135. }