locreateW.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /***************************************************************************
  2. * Licensed Materials - Property of IBM and/or HCL
  3. *
  4. * IBM Informix Client-SDK
  5. *
  6. * Copyright IBM Corporation 1997, 2013.
  7. * (c) Copyright HCL Technologies Ltd. 2017. All Rights Reserved.
  8. *
  9. *
  10. *
  11. * Title: locreateW.c (Unicode counterpart of locreate.c)
  12. *
  13. * Description: To create a smart large object and insert it into the
  14. * database
  15. * -- the column created is the 'advert' column of the
  16. * table 'item' (datatype - CLOB)
  17. *
  18. ***************************************************************************
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <sys/stat.h>
  24. #include <wchar.h>
  25. #include <errno.h>
  26. #ifndef NO_WIN32
  27. #include <io.h>
  28. #include <windows.h>
  29. #include <conio.h>
  30. #endif /*NO_WIN32*/
  31. #include <fcntl.h>
  32. #include "infxcli.h"
  33. #define BUFFER_LEN 25
  34. #define BUFFER_LENW BUFFER_LEN * sizeof(SQLWCHAR)
  35. #define ERRMSG_LEN 200
  36. SQLWCHAR defDsnW[] = L"odbc_demo";
  37. SQLCHAR defDsn[] = "odbc_demo";
  38. SQLINTEGER checkError (SQLRETURN rc,
  39. SQLSMALLINT handleType,
  40. SQLHANDLE handle,
  41. SQLCHAR* errmsg)
  42. {
  43. SQLRETURN retcode = SQL_SUCCESS;
  44. SQLSMALLINT errNum = 1;
  45. SQLWCHAR sqlStateW[6];
  46. SQLCHAR *sqlState;
  47. SQLINTEGER nativeError;
  48. SQLWCHAR errMsgW[ERRMSG_LEN];
  49. SQLCHAR *errMsg;
  50. SQLSMALLINT textLengthPtr;
  51. if ((rc != SQL_SUCCESS) && (rc != SQL_SUCCESS_WITH_INFO))
  52. {
  53. while (retcode != SQL_NO_DATA)
  54. {
  55. retcode = SQLGetDiagRecW (handleType, handle, errNum, sqlStateW, &nativeError, errMsgW, ERRMSG_LEN, &textLengthPtr);
  56. if (retcode == SQL_INVALID_HANDLE)
  57. {
  58. fprintf (stderr, "checkError function was called with an invalid handle!!\n");
  59. return 1;
  60. }
  61. if ((retcode == SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO))
  62. {
  63. sqlState = (SQLCHAR *) malloc (wcslen(sqlStateW) + sizeof(char));
  64. if (sqlState == NULL)
  65. {
  66. return -1; /* internal error within checkError, let caller handle it */
  67. }
  68. wcstombs( (char *) sqlState, sqlStateW, wcslen(sqlStateW)
  69. + sizeof(char));
  70. errMsg = (SQLCHAR *) malloc (wcslen(errMsgW) + sizeof(char));
  71. if (errMsg == NULL)
  72. {
  73. return -1; /* internal error within checkError, let caller handle it */
  74. }
  75. wcstombs( (char *) errMsg, errMsgW, wcslen(errMsgW)
  76. + sizeof(char));
  77. fprintf (stderr, "ERROR: %d: %s : %s \n", nativeError, sqlState, errMsg);
  78. }
  79. errNum++;
  80. }
  81. fprintf (stderr, "%s\n", errmsg);
  82. return 1; /* all errors on this handle have been reported */
  83. }
  84. else
  85. return 0; /* no errors to report */
  86. }
  87. int main (long argc,
  88. char* argv[])
  89. {
  90. /* Declare variables
  91. */
  92. /* Handles */
  93. SQLHDBC hdbc;
  94. SQLHENV henv;
  95. SQLHSTMT hstmt;
  96. /* Smart large object file descriptor */
  97. SQLINTEGER lofd;
  98. SQLLEN lofd_valsize = 0;
  99. /* Smart large object pointer structure */
  100. SQLWCHAR* loptr_bufferW;
  101. SQLSMALLINT loptr_size;
  102. SQLLEN loptr_valsize = 0;
  103. /* Smart large object specification structure */
  104. SQLWCHAR* lospec_bufferW;
  105. SQLSMALLINT lospec_size;
  106. SQLLEN lospec_valsize = 0;
  107. /* Write buffer */
  108. SQLWCHAR* write_bufferW;
  109. off_t write_size;
  110. SQLLEN write_valsize = 0;
  111. size_t status;
  112. struct stat statbuf;
  113. int fd;
  114. /* Miscellaneous variables */
  115. SQLWCHAR *dsnW; /*name of the DSN used for connecting to the database*/
  116. SQLRETURN rc = 0;
  117. SQLINTEGER in;
  118. SQLWCHAR verInfoBufferW[BUFFER_LENW];
  119. SQLSMALLINT verInfoLen;
  120. SQLCHAR* lo_file_name = (SQLCHAR *) "advert.txt";
  121. SQLWCHAR colnameW[BUFFER_LEN] = L"item.advert";
  122. SQLLEN colname_size = SQL_NTS;
  123. SQLINTEGER mode = LO_RDWR;
  124. SQLLEN cbMode = 0;
  125. SQLWCHAR* insertStmtW = (SQLWCHAR *) L"INSERT INTO item VALUES (1005, 'Helmet', 235, 'Each', '39.95', ?)";
  126. int lenArgv1;
  127. /* STEP 1. Get data source name from command line (or use default)
  128. ** Allocate environment handle and set ODBC version
  129. ** Allocate connection handle
  130. ** Establish the database connection
  131. ** Get version information from the database server
  132. ** -- if version < 9.x (not UDO enabled), exit with error message
  133. ** Allocate the statement handle
  134. */
  135. /* If(dsn is not explicitly passed in as arg) */
  136. if (argc != 2)
  137. {
  138. /* Use default dsnW - odbc_demo */
  139. fprintf (stdout, "\nUsing default DSN : %s\n", defDsn);
  140. dsnW = (SQLWCHAR *) malloc( wcslen(defDsnW) * sizeof(SQLWCHAR)
  141. + sizeof(SQLWCHAR) );
  142. if (dsnW == NULL)
  143. {
  144. fprintf(stdout, "Failed to allocate memory for DSN\n");
  145. goto Exit;
  146. }
  147. wcscpy ((SQLWCHAR *)dsnW, (SQLWCHAR *)defDsnW);
  148. }
  149. else
  150. {
  151. /* Use specified dsnW */
  152. lenArgv1 = strlen((char *)argv[1]);
  153. dsnW = (SQLWCHAR *) malloc (lenArgv1 * sizeof(SQLWCHAR)
  154. + sizeof(SQLWCHAR));
  155. if (dsnW == NULL)
  156. {
  157. fprintf(stdout, "Failed to allocate memory for DSN\n");
  158. goto Exit;
  159. }
  160. mbstowcs (dsnW, (char *)argv[1], lenArgv1 + sizeof(char));
  161. fprintf (stdout, "\nUsing specified DSN : %s\n", argv[1]);
  162. }
  163. /* Allocate the Environment handle */
  164. rc = SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
  165. if (rc != SQL_SUCCESS)
  166. {
  167. fprintf (stdout, "Environment Handle Allocation failed\nExiting!!\n");
  168. return (1);
  169. }
  170. /* Set the ODBC version to 3.0 */
  171. rc = SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, 0);
  172. if (checkError (rc, SQL_HANDLE_ENV, henv, (SQLCHAR *) "Error in Step 1 -- SQLSetEnvAttr failed\nExiting!!\n"))
  173. return (1);
  174. /* Allocate the connection handle */
  175. rc = SQLAllocHandle (SQL_HANDLE_DBC, henv, &hdbc);
  176. if (checkError (rc, SQL_HANDLE_ENV, henv, (SQLCHAR *) "Error in Step 1 -- Connection Handle Allocation failed\nExiting!!\n"))
  177. return (1);
  178. /* Establish the database connection */
  179. rc = SQLConnectW (hdbc, dsnW, SQL_NTS, (SQLWCHAR *) L"", SQL_NTS, (SQLWCHAR *) L"", SQL_NTS);
  180. if (checkError (rc, SQL_HANDLE_DBC, hdbc, (SQLCHAR *) "Error in Step 1 -- SQLConnect failed\n"))
  181. return (1);
  182. /* Get version information from the database server
  183. If version < 9.x (not UDO enabled), exit with error message */
  184. rc = SQLGetInfoW (hdbc, SQL_DBMS_VER, verInfoBufferW, BUFFER_LENW, &verInfoLen);
  185. if (checkError (rc, SQL_HANDLE_DBC, hdbc, (SQLCHAR *) "Error in Step 1 -- SQLGetInfo failed\n"))
  186. return 1;
  187. if ((wcsncmp ((SQLWCHAR *) verInfoBufferW, L"09", 2)) < 0 )
  188. {
  189. fprintf (stdout, "\n** This test can only be run against database server -- version 9 or higher **\n");
  190. return 1;
  191. }
  192. /* Allocate the statement handle */
  193. rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt );
  194. if (checkError (rc, SQL_HANDLE_DBC, hdbc, (SQLCHAR *) "Error in Step 1 -- Statement Handle Allocation failed\nExiting!!"))
  195. return (1);
  196. fprintf (stdout, "STEP 1 done...connected to database\n");
  197. /* STEP 2. Get the size of the smart large object specification structure
  198. ** Allocate a buffer to hold the structure
  199. ** Create a default smart large object specification structure
  200. ** Reset the statement parameters
  201. */
  202. /* Get the size of a smart large object specification structure */
  203. rc = SQLGetInfo (hdbc, SQL_INFX_LO_SPEC_LENGTH, &lospec_size,
  204. sizeof(lospec_size), NULL);
  205. if (checkError (rc, SQL_HANDLE_DBC, hdbc, (SQLCHAR *) "Error in Step 2 -- SQLGetInfo failed\n"))
  206. goto Exit;
  207. /* Allocate a buffer to hold the smart large object specification
  208. structure*/
  209. lospec_bufferW = malloc (lospec_size);
  210. if (lospec_bufferW == NULL)
  211. {
  212. fprintf(stdout, "Failed to allocate memory for the smart large object specification buffer \n");
  213. goto Exit;
  214. }
  215. /* Create a default smart large object specification structure */
  216. rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT_OUTPUT, SQL_C_BINARY,
  217. SQL_INFX_UDT_FIXED, (UDWORD)lospec_size, 0,
  218. lospec_bufferW, lospec_size, &lospec_valsize);
  219. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 2 -- SQLBindParameter failed\n"))
  220. goto Exit;
  221. rc = SQLExecDirectW (hstmt, (SQLWCHAR *) L"{call ifx_lo_def_create_spec(?)}", SQL_NTS);
  222. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 2 -- SQLExecDirect failed\n"))
  223. goto Exit;
  224. /* Reset the statement parameters */
  225. rc = SQLFreeStmt (hstmt, SQL_RESET_PARAMS);
  226. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 2 -- SQLFreeStmt failed\n"))
  227. goto Exit;
  228. fprintf (stdout, "STEP 2 done...default smart large object specification structure created\n");
  229. /* STEP 3. Initialise the smart large object specification structure with
  230. ** values for the database column where the smart large object is
  231. ** being inserted
  232. ** Reset the statement parameters
  233. */
  234. /* Initialise the smart large object specification structure */
  235. rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_CHAR,
  236. BUFFER_LEN, 0, colnameW, BUFFER_LENW, &colname_size);
  237. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 3 -- SQLBindParameter failed (param 1)\n"))
  238. goto Exit;
  239. lospec_valsize = lospec_size;
  240. rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT_OUTPUT, SQL_C_BINARY,
  241. SQL_INFX_UDT_FIXED, (UDWORD)lospec_size, 0, lospec_bufferW,
  242. lospec_size, &lospec_valsize);
  243. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 3 -- SQLBindParameter failed (param 2)\n"))
  244. goto Exit;
  245. rc = SQLExecDirectW (hstmt, (SQLWCHAR *) L"{call ifx_lo_col_info(?, ?)}", SQL_NTS);
  246. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 3 -- SQLExecDirect failed\n"))
  247. goto Exit;
  248. /* Reset the statement parameters */
  249. rc = SQLFreeStmt (hstmt, SQL_RESET_PARAMS);
  250. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 3 -- SQLFreeStmt failed\n"))
  251. goto Exit;
  252. fprintf(stdout, "STEP 3 done...smart large object specification structure initialised\n");
  253. /* STEP 4. Get the size of the smart large object pointer structure
  254. ** Allocate a buffer to hold the structure.
  255. */
  256. /* Get the size of the smart large object pointer structure */
  257. rc = SQLGetInfo (hdbc, SQL_INFX_LO_PTR_LENGTH, &loptr_size, sizeof(loptr_size), NULL);
  258. if (checkError (rc, SQL_HANDLE_DBC, hdbc, (SQLCHAR *) "Error in Step 4 -- SQLGetInfo failed\n"))
  259. goto Exit;
  260. /* Allocate a buffer to hold the smart large object pointer structure */
  261. loptr_bufferW = malloc (loptr_size);
  262. if (loptr_bufferW == NULL)
  263. {
  264. fprintf(stdout, "Failed to allocate memory for the smart large object pointer structure buffer \n");
  265. goto Exit;
  266. }
  267. fprintf (stdout, "STEP 4 done...smart large object pointer structure allocated\n");
  268. /* STEP 5. Create a new smart large object.
  269. ** Reset the statement parameters
  270. */
  271. /* Create a new smart large object */
  272. rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_INFX_UDT_FIXED,
  273. (UDWORD)lospec_size, 0, lospec_bufferW, lospec_size, &lospec_valsize);
  274. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 5 -- SQLBindParameter failed (param 1)\n"))
  275. goto Exit;
  276. rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER,
  277. (UDWORD)0, 0, &mode, sizeof(mode), &cbMode);
  278. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 5 -- SQLBindParameter failed (param 2)\n"))
  279. goto Exit;
  280. loptr_valsize = loptr_size;
  281. rc = SQLBindParameter (hstmt, 3, SQL_PARAM_INPUT_OUTPUT, SQL_C_BINARY, SQL_INFX_UDT_FIXED,
  282. (UDWORD)loptr_size, 0, loptr_bufferW, loptr_size, &loptr_valsize);
  283. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 5 -- SQLBindParameter failed (param 3)\n"))
  284. goto Exit;
  285. rc = SQLBindParameter (hstmt, 4, SQL_PARAM_OUTPUT, SQL_C_SLONG, SQL_INTEGER,
  286. (UDWORD)0, 0, &lofd, sizeof(lofd), &lofd_valsize);
  287. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 5 -- SQLBindParameter failed (param 4)\n"))
  288. goto Exit;
  289. rc = SQLExecDirectW (hstmt, (SQLWCHAR *) L"{call ifx_lo_create(?, ?, ?, ?)}", SQL_NTS);
  290. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 5 -- SQLExecDirect failed\n"))
  291. goto Exit;
  292. /* Reset the statement parameters */
  293. rc = SQLFreeStmt (hstmt, SQL_RESET_PARAMS);
  294. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 5 -- SQLFreeStmt failed\n"))
  295. goto Exit;
  296. fprintf (stdout, "STEP 5 done...smart large object created\n");
  297. /* STEP 6. Open the file containing data for the new smart large object
  298. ** Allocate a buffer to hold the smart large object data
  299. ** Read data from the input file into the smart large object data buffer
  300. ** Write data from the data buffer into the new smart large object.
  301. ** Reset the statement parameters
  302. */
  303. /* Get the size of the file containing data for the new smart large object */
  304. if (stat( (char *)lo_file_name,&statbuf) == -1)
  305. {
  306. fprintf (stdout, "Error %d reading %s\n", errno, lo_file_name);
  307. exit(1);
  308. }
  309. write_size = statbuf.st_size;
  310. /* Allocate a buffer to hold the smart large object data */
  311. write_bufferW = malloc (write_size + 1);
  312. if (write_bufferW == NULL)
  313. {
  314. fprintf(stdout, "Failed to allocate memory for the smart large object data buffer \n");
  315. goto Exit;
  316. }
  317. /* Read smart large object data from file */
  318. fd = open ((char *) lo_file_name, O_RDONLY);
  319. if (fd == -1)
  320. {
  321. fprintf (stdout, "Error %d creating file descriptor for %s\n", errno, lo_file_name);
  322. exit(1);
  323. }
  324. status = read (fd, write_bufferW, write_size);
  325. if (status < 0)
  326. {
  327. fprintf (stdout, "Error %d reading %s\n", errno, lo_file_name);
  328. }
  329. if (close(fd) < 0)
  330. {
  331. fprintf (stdout, "Error %d closing the file %s\n", errno, lo_file_name);
  332. exit(1);
  333. }
  334. write_bufferW[write_size] = L'\0';
  335. write_valsize = write_size;
  336. /* Write data from the data buffer into the new smart large object */
  337. rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER,
  338. (UDWORD)0, 0, &lofd, sizeof(lofd), &lofd_valsize);
  339. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 6 -- SQLBindParameter failed (param 1)\n"))
  340. goto Exit;
  341. rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
  342. (UDWORD)write_size, 0, write_bufferW, write_size, &write_valsize);
  343. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 6 -- SQLBindParameter failed (param 2)\n"))
  344. goto Exit;
  345. rc = SQLExecDirectW (hstmt, (SQLWCHAR *) L"{call ifx_lo_write(?, ?)}", SQL_NTS);
  346. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 6 -- SQLExecDirect failed\n"))
  347. goto Exit;
  348. /* Reset the statement parameters */
  349. rc = SQLFreeStmt (hstmt, SQL_RESET_PARAMS);
  350. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 6 -- SQLFreeStmt failed\n"))
  351. goto Exit;
  352. fprintf (stdout, "STEP 6 done...data written to new smart large object\n");
  353. /* STEP 7. Insert the new smart large object into the database.
  354. ** Reset the statement parameters
  355. */
  356. /* Insert the new smart large object into the database */
  357. loptr_valsize = loptr_size;
  358. rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_INFX_UDT_FIXED,
  359. (UDWORD)loptr_size, 0, loptr_bufferW, loptr_size, &loptr_valsize);
  360. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 7 -- SQLBindParameter failed\n"))
  361. goto Exit;
  362. rc = SQLExecDirectW (hstmt, insertStmtW, SQL_NTS);
  363. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 7 -- SQLExecDirect failed\n"))
  364. goto Exit;
  365. /* Reset the statement parameters */
  366. rc = SQLFreeStmt (hstmt, SQL_RESET_PARAMS);
  367. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 7 -- SQLFreeStmt failed\n"))
  368. goto Exit;
  369. fprintf (stdout, "STEP 7 done...smart large object inserted into the database\n");
  370. /* STEP 8. Close the smart large object. */
  371. rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
  372. (UDWORD)0, 0, &lofd, sizeof(lofd), &lofd_valsize);
  373. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 8 -- SQLBindParameter failed\n"))
  374. goto Exit;
  375. rc = SQLExecDirectW (hstmt, (SQLWCHAR *) L"{call ifx_lo_close(?)}", SQL_NTS);
  376. if (checkError (rc, SQL_HANDLE_STMT, hstmt, (SQLCHAR *) "Error in Step 8 -- SQLExecDirect failed\n"))
  377. goto Exit;
  378. fprintf (stdout, "STEP 8 done...smart large object closed\n");
  379. /* STEP 9. Free the allocated buffers */
  380. if (lospec_bufferW)
  381. free (lospec_bufferW);
  382. if (loptr_bufferW)
  383. free (loptr_bufferW);
  384. if (write_bufferW)
  385. free (write_bufferW);
  386. fprintf (stdout, "STEP 9 done...smart large object buffers freed\n");
  387. Exit:
  388. /* CLEANUP: Close the statement handle
  389. ** Free the statement handle
  390. ** Disconnect from the datasource
  391. ** Free the connection and environment handles
  392. ** Exit
  393. */
  394. /* Close the statement handle */
  395. SQLFreeStmt (hstmt, SQL_CLOSE);
  396. /* Free the statement handle */
  397. SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
  398. /* Disconnect from the data source */
  399. SQLDisconnect (hdbc);
  400. /* Free the environment handle and the database connection handle */
  401. SQLFreeHandle (SQL_HANDLE_DBC, hdbc);
  402. SQLFreeHandle (SQL_HANDLE_ENV, henv);
  403. fprintf (stdout,"\n\nHit <Enter> to terminate the program...\n\n");
  404. in = getchar ();
  405. return (rc);
  406. }