Guest User

Untitled

a guest
Sep 27th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. /*
  2. Permission to use, copy, modify, and/or distribute this software for any
  3. purpose with or without fee is hereby granted, provided that the above
  4. copyright notice and this permission notice appear in all copies.
  5.  
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14.  
  15. #include <string.h>
  16. #include <time.h>
  17. #include <stdlib.h>
  18. #include <sql.h>
  19. #include <sqltypes.h>
  20. #include <sqlext.h>
  21. #include <sys/timeb.h>
  22.  
  23. #define MAX_FIELD_SIZE 1024
  24. #define MAX_VALUE_SIZE 1048576
  25.  
  26.  
  27.  
  28. int main() {
  29. HENV m_hEnv;
  30. HDBC m_hDBC;
  31. HSTMT m_hStmt;
  32. SQLRETURN ret;
  33. SQLUSMALLINT canHaveMoreResults;
  34.  
  35. if( SQL_SUCCEEDED(SQLAllocEnv( &m_hEnv )) ) {
  36.  
  37. if( SQL_SUCCEEDED(SQLAllocHandle( SQL_HANDLE_DBC, m_hEnv, &m_hDBC )) ) {
  38. SQLSetConnectOption( m_hDBC, SQL_LOGIN_TIMEOUT,5 );
  39.  
  40. ret = SQLDriverConnect(
  41. m_hDBC,
  42. NULL,
  43. "DRIVER={MySQL};HOST=localhost;USERNAME=test;PASSWORD=;DATABASE=test;",
  44. SQL_NTS,
  45. NULL,
  46. 0,
  47. NULL,
  48. SQL_DRIVER_NOPROMPT
  49. );
  50.  
  51. if( SQL_SUCCEEDED(ret) ) {
  52. int iterations = 10000;
  53. int i = 0;
  54. struct timeb start;
  55.  
  56. ftime(&start);
  57.  
  58. for (i =0 ; i <= iterations; i ++) {
  59. SQLAllocHandle(SQL_HANDLE_STMT, m_hDBC, &m_hStmt);
  60.  
  61. SQLExecDirect(m_hStmt, "select 1 + 1 as test;", SQL_NTS);
  62.  
  63. while ( SQL_SUCCEEDED(SQLFetch(m_hStmt) )) {
  64. //printf("sql query succeeded\n");
  65. }
  66.  
  67. SQLFreeHandle(SQL_HANDLE_STMT, m_hStmt);
  68. }
  69.  
  70. struct timeb stop;
  71. ftime(&stop);
  72.  
  73. double elapsed = ((stop.time * 1000 + stop.millitm) - (start.time * 1000 + start.millitm));
  74.  
  75. printf("%d queries issued in %f seconds, %f/sec\n", iterations, (double) elapsed / 1000, iterations/((double) elapsed / 1000));
  76. }
  77. else {
  78. printf("here3\n");
  79. printError("SQLDriverConnect", m_hDBC, SQL_HANDLE_DBC);
  80. }
  81. }
  82. else {
  83. printError("SQLAllocHandle - dbc", m_hEnv, SQL_HANDLE_ENV);
  84. }
  85. }
  86. else {
  87. printError("SQLAllocHandle - env", m_hEnv, SQL_HANDLE_ENV);
  88. }
  89.  
  90. //SQLFreeHandle(SQL_HANDLE_DBC, m_hDBC);
  91. //SQLFreeHandle(SQL_HANDLE_ENV, m_hEnv);
  92.  
  93. return 0;
  94. }
  95.  
  96. void printError(const char *fn, SQLHANDLE handle, SQLSMALLINT type)
  97. {
  98. SQLINTEGER i = 0;
  99. SQLINTEGER native;
  100. SQLCHAR state[ 7 ];
  101. SQLCHAR text[256];
  102. SQLSMALLINT len;
  103. SQLRETURN ret;
  104.  
  105. printf(
  106. "\n"
  107. "The driver reported the following diagnostics whilst running "
  108. "%s\n\n",
  109. fn
  110. );
  111.  
  112. do {
  113. ret = SQLGetDiagRec(type, handle, ++i, state, &native, text, sizeof(text), &len );
  114. if (SQL_SUCCEEDED(ret))
  115. printf("%s:%ld:%ld:%s\n", state, (long int) i, (long int) native, text);
  116. }
  117. while( ret == SQL_SUCCESS );
  118. }
Add Comment
Please, Sign In to add comment