LCOV - code coverage report
Current view: top level - src/odbc/unittests - insert_speed.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 28 28 100.0 %
Date: 2025-01-18 11:50:39 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : #include <assert.h>
       3             : 
       4             : #define SQL_QUERY_LENGTH 80
       5             : 
       6             : /* test correctly inserted data after insert */
       7             : 
       8             : /* I don't remember where this test came ... - freddy77 */
       9             : 
      10             : static void
      11          16 : insert_test(bool manual)
      12             : {
      13          16 :         SQLLEN sql_nts = SQL_NTS;
      14          16 :         SQLINTEGER id = 0;
      15             :         char string[64];
      16          16 :         SQLINTEGER commit_off = SQL_AUTOCOMMIT_OFF;
      17          16 :         SQLINTEGER commit_on = SQL_AUTOCOMMIT_ON;
      18             : 
      19          16 :         if (manual)
      20           8 :                 CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, TDS_INT2PTR(commit_off), SQL_IS_INTEGER, "SI");
      21             : 
      22          16 :         odbc_reset_statement();
      23             : 
      24          16 :         CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, sizeof(id), 0, &id, 0, &sql_nts, "SI");
      25          16 :         CHKBindParameter(2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, sizeof(string), 0, string, 0, &sql_nts, "SI");
      26             : 
      27          16 :         CHKPrepare(T("insert into test values (?, ?)"), SQL_NTS, "SI");
      28         336 :         for (id = 0; id < 20; id++) {
      29         320 :                 sprintf(string, "This is a test (%d)", (int) id);
      30         320 :                 CHKExecute("SI");
      31             :         }
      32             : 
      33          16 :         if (manual) {
      34           8 :                 SQLEndTran(SQL_HANDLE_DBC, odbc_conn, SQL_COMMIT);
      35           8 :                 SQLSetConnectAttr(odbc_conn, SQL_ATTR_AUTOCOMMIT, TDS_INT2PTR(commit_on), SQL_IS_INTEGER);
      36             :         }
      37          16 :         odbc_reset_statement();
      38          16 : }
      39             : 
      40             : int
      41           8 : main(void)
      42             : {
      43           8 :         odbc_connect();
      44             : 
      45           8 :         odbc_command_with_result(odbc_stmt, "DROP TABLE test");
      46           8 :         odbc_command("CREATE TABLE test(i int, c varchar(40))");
      47             : 
      48             :         /* manual commit */
      49           8 :         insert_test(true);
      50             : 
      51           8 :         odbc_command("DELETE FROM test");
      52             : 
      53             :         /* auto commit */
      54           8 :         insert_test(false);
      55             : 
      56           8 :         odbc_command("DROP TABLE test");
      57             : 
      58           8 :         odbc_disconnect();
      59             : 
      60             :         return 0;
      61             : }

Generated by: LCOV version 1.13