Ejemplo n.º 1
0
int lodbc_environment_create(lua_State *L, SQLHENV henv, uchar own){
  lodbc_env *env;
  uchar is_new = 0;
  if(henv == SQL_NULL_HANDLE){
    SQLRETURN ret = SQLAllocHandle(hENV, SQL_NULL_HANDLE, &henv);
    if (lodbc_iserror(ret))
      return lodbc_faildirect(L, "error creating environment.");
    own = 1;
    is_new = 1;
  }

  env = lutil_newudatap(L, lodbc_env, LODBC_ENV);
  memset(env, 0, sizeof(lodbc_env));
  if(!own)env->flags |= LODBC_FLAG_DONT_DESTROY;
  env->handle = henv;

  if(is_new){
    int top = lua_gettop(L);
    SQLRETURN ret = env_set_uint_attr_(L, env, SQL_ATTR_ODBC_VERSION, LODBC_ODBC3_C(SQL_OV_ODBC3, SQL_OV_ODBC2) );
    if(lodbc_is_fail(L,ret)){
      SQLFreeHandle (hENV, henv);
      env->flags &= ~LODBC_FLAG_DESTROYED;
      return ret;
    }
    lua_settop(L, top);
  }

  return 1;
}
Ejemplo n.º 2
0
/*
** Retrieves data from the i_th column in the current row
** Input
**   types: index in sack of column types table
**   hstmt: statement handle
**   i: column number
** Returns:
**   0 if successfull, non-zero otherwise;
*/
int lodbc_push_column(lua_State *L, int coltypes, const SQLHSTMT hstmt, SQLUSMALLINT i) {
  const char *tname;
  char type;
  lua_rawgeti (L, coltypes, i);   /* typename of the column */
  tname = lua_tostring(L, -1);
  if (!tname) return lodbc_faildirect(L, "invalid type in table.");
  type = tname[1];
  lua_pop(L, 1); /* pops type name */
  return lodbc_push_column_value(L,hstmt,i,type);
}
Ejemplo n.º 3
0
int lodbc_set_str_attr_(lua_State*L, SQLSMALLINT HandleType, SQLHANDLE Handle, 
    SQLINTEGER optnum, const char* value, size_t len)
{
    SQLRETURN ret;
#if (LODBC_ODBCVER >= 0x0300)
    ret = select_set_attr_v3(HandleType)(Handle,optnum,(SQLPOINTER)value,len);
#else 
    if(HandleType == hENV) return lodbc_faildirect(L, "not supported."); 
    ret = select_set_attr   (HandleType)(Handle,optnum,(SQLUINTEGER)value);
#endif
    if(lodbc_iserror(ret)) return lodbc_fail(L, HandleType, Handle);
    return lodbc_pass(L);
}
Ejemplo n.º 4
0
int lodbc_get_uint_attr_(lua_State*L, SQLSMALLINT HandleType, SQLHANDLE Handle, SQLINTEGER optnum){
    SQLUINTEGER res;
    SQLRETURN ret;
#if (LODBC_ODBCVER >= 0x0300)
    SQLINTEGER dummy;
    ret = select_get_attr_v3(HandleType)(Handle, optnum, (SQLPOINTER)&res, sizeof(res), &dummy);
#else 
    if(HandleType == hENV) return lodbc_faildirect(L, "not supported."); 
    ret = select_get_attr   (HandleType)(Handle, optnum, (SQLPOINTER)&res);
#endif

    if(ret == LODBC_ODBC3_C(SQL_NO_DATA,SQL_NO_DATA_FOUND)) return 0;
    if(lodbc_iserror(ret)) return lodbc_fail(L, HandleType, Handle);
    lua_pushnumber(L,res);
    return 1;
}
Ejemplo n.º 5
0
int lodbc_get_str_attr_(lua_State*L, SQLSMALLINT HandleType, SQLHANDLE Handle, SQLINTEGER optnum){
#if (LODBC_ODBCVER >= 0x0300)
    SQLINTEGER got;
    char buffer[256];
#else 
    char buffer[SQL_MAX_OPTION_STRING_LENGTH+1];
#endif
    SQLRETURN ret;

#if (LODBC_ODBCVER >= 0x0300)
    ret = select_get_attr_v3(HandleType)(Handle, optnum, (SQLPOINTER)buffer, 255, &got);
#else 
    if(HandleType == hENV) return lodbc_faildirect(L, "not supported."); 
    ret = select_get_attr   (HandleType)(Handle, optnum, (SQLPOINTER)&buffer);
#endif

    if(ret == LODBC_ODBC3_C(SQL_NO_DATA,SQL_NO_DATA_FOUND)) return 0;
    if(lodbc_iserror(ret)) return lodbc_fail(L, HandleType, Handle);

#if (LODBC_ODBCVER >= 0x0300)
    if(got > 255){
        char* tmp = malloc(got+1);
        if(!tmp)
            return LODBC_ALLOCATE_ERROR(L);
        ret = select_get_attr_v3(HandleType)(Handle, optnum, (SQLPOINTER)tmp, got, &got);
        if(lodbc_iserror(ret)){
            free(tmp);
            if(ret == SQL_NO_DATA) return 0;
            return lodbc_fail(L, HandleType, Handle);
        }
        lua_pushstring(L, tmp);
        free(tmp);
    }
    else 
#endif
    lua_pushstring(L, buffer);

    return 1;
}
Ejemplo n.º 6
0
Archivo: lenv.c Proyecto: ld-test/odbc
int lodbc_environment_create(lua_State *L, SQLHENV henv, uchar own) {
    lodbc_env *env;
    uchar is_new = 0;
    if(henv == SQL_NULL_HANDLE) {
        SQLRETURN ret = SQLAllocHandle(hENV, SQL_NULL_HANDLE, &henv);
        if (lodbc_iserror(ret))
            return lodbc_faildirect(L, "error creating environment.");
        own = 1;
        is_new = 1;
    }

    env = lutil_newudatap(L, lodbc_env, LODBC_ENV);
    memset(env, 0, sizeof(lodbc_env));
    if(!own)env->flags |= LODBC_FLAG_DONT_DESTROY;
    env->handle = henv;

    env->conn_list_ref = LUA_NOREF;
    if(LODBC_OPT_INT(ENV_AUTOCLOSECNN)) {
        int top = lua_gettop(L);
        lua_pushvalue(L, -1);
        lua_pushboolean(L, 1);
        lodbc_pcall_method(L, "setautoclosecnn", 1, 0, 0);
        lua_settop(L, top);
    }

    if(is_new) {
        int top = lua_gettop(L);
        SQLRETURN ret = env_set_uint_attr_(L, env, SQL_ATTR_ODBC_VERSION, LODBC_ODBC3_C(SQL_OV_ODBC3, SQL_OV_ODBC2) );
        if(lodbc_is_fail(L,ret)) {
            SQLFreeHandle (hENV, henv);
            env->flags &= ~LODBC_FLAG_DESTROYED;
            return ret;
        }
        lua_settop(L, top);
    }

    return 1;
}