Connecting to Splice Machine with C and ODBC

This topic shows you how to compile and run a sample C program that exercises the Splice Machine ODBC driver. The listODBCdriver program verifies that the driver is correctly installed and available.

Compile and Run the Sample Program

This section walks you through compiling and running the listODBCdriver example program, which simply displays information about the installed driver.

  1. Install the ODBC driver

    Follow our instructions for installing the driver on Unix or Windows.

  2. Copy the example program code

    You can copy and paste the code below:

    #include <stdio.h>
    #include <sql.h>
    #include <sqlext.h>
        
    main() {
       SQLHENV env;
       char driver[256];
       char attr[256];
       SQLSMALLINT driver_ret;
       SQLSMALLINT attr_ret;
       SQLUSMALLINT direction;
       SQLRETURN ret;
        
       SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
       SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
        
       direction = SQL_FETCH_FIRST;
       while(SQL_SUCCEEDED(ret = SQLDrivers(env, direction,
             driver, sizeof(driver), &driver_ret,
             attr, sizeof(attr), &attr_ret))) {
             direction = SQL_FETCH_NEXT;
          printf("%s - %s\n", driver, attr);
          if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata truncation\n");
          }
    }                    
    
  3. Compile it

    #!/bin/bash
    # gcc -I /usr/local/splice/unixODBC/include listODBCdriver.c -o listODBCdriver -L/usr/local/splice/lib -lodbc -lodbcinst -lodbccr
    
  4. Run the program

    Run the compiled listODBCdriver:

    prompt:~$ ./listODBCdriver
    

    The command should display a result like the following:

    Splice Machine - Description=Splice Machine ODBC Driver