LCOV - code coverage report
Current view: top level - src/odbc/unittests - insert_speed.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 38 38 100.0 %
Date: 2024-04-18 21:21:48 Functions: 3 3 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : #include <assert.h>
       3             : 
       4             : static char software_version[] = "$Id: insert_speed.c,v 1.10 2011-07-12 10:16:59 freddy77 Exp $";
       5             : static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
       6             : 
       7             : #define SQL_QUERY_LENGTH 80
       8             : 
       9             : /* test correctly inserted data after insert */
      10             : 
      11             : /* I don't remember where this test came ... - freddy77 */
      12             : 
      13             : static void
      14           8 : insert_test_auto(void)
      15             : {
      16           8 :         SQLLEN sql_nts = SQL_NTS;
      17           8 :         SQLINTEGER id = 0;
      18             :         char string[64];
      19             : 
      20           8 :         odbc_reset_statement();
      21             : 
      22           8 :         CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, sizeof(id), 0, &id, 0, &sql_nts, "SI");
      23           8 :         CHKBindParameter(2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, sizeof(string), 0, string, 0, &sql_nts, "SI");
      24             : 
      25           8 :         CHKPrepare(T("insert into test values (?, ?)"), SQL_NTS, "SI");
      26         168 :         for (id = 0; id < 20; id++) {
      27         160 :                 sprintf(string, "This is a test (%d)", (int) id);
      28         160 :                 CHKExecute("SI");
      29             :         }
      30             : 
      31           8 :         odbc_reset_statement();
      32           8 : }
      33             : 
      34             : 
      35             : static void
      36           8 : insert_test_man(void)
      37             : {
      38           8 :         SQLLEN sql_nts = SQL_NTS;
      39           8 :         SQLINTEGER commit_off = SQL_AUTOCOMMIT_OFF;
      40           8 :         SQLINTEGER commit_on = SQL_AUTOCOMMIT_ON;
      41           8 :         SQLINTEGER id = 0;
      42             : 
      43             :         char string[64];
      44             : 
      45           8 :         CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, TDS_INT2PTR(commit_off), SQL_IS_INTEGER, "SI");
      46             : 
      47           8 :         odbc_reset_statement();
      48             : 
      49           8 :         CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, sizeof(id), 0, &id, 0, &sql_nts, "SI");
      50           8 :         CHKBindParameter(2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, sizeof(string), 0, string, 0, &sql_nts, "SI");
      51             : 
      52           8 :         CHKPrepare(T("insert into test values (?, ?)"), SQL_NTS, "SI");
      53         168 :         for (id = 0; id < 20; id++) {
      54         160 :                 sprintf(string, "This is a test (%d)", (int) id);
      55         160 :                 CHKExecute("SI");
      56             :         }
      57             : 
      58           8 :         SQLEndTran(SQL_HANDLE_DBC, odbc_conn, SQL_COMMIT);
      59           8 :         SQLSetConnectAttr(odbc_conn, SQL_ATTR_AUTOCOMMIT, TDS_INT2PTR(commit_on), SQL_IS_INTEGER);
      60           8 :         odbc_reset_statement();
      61           8 : }
      62             : 
      63             : int
      64           8 : main(int argc, char **argv)
      65             : {
      66           8 :         odbc_connect();
      67             : 
      68           8 :         odbc_command_with_result(odbc_stmt, "DROP TABLE test");
      69           8 :         odbc_command("CREATE TABLE test(i int, c varchar(40))");
      70             : 
      71           8 :         insert_test_man();
      72             : 
      73           8 :         odbc_command("DELETE FROM test");
      74             : 
      75           8 :         insert_test_auto();
      76             : 
      77           8 :         odbc_command("DROP TABLE test");
      78             : 
      79           8 :         odbc_disconnect();
      80             : 
      81             :         return 0;
      82             : }

Generated by: LCOV version 1.13