Fetch unique SQL result into variable

Hi All,

Im developing a security dll that authenticates users by setting up an ODBC connection to an Oracle DB. The relevant code I have developed so far looks like this. At this point, I am just trying to save the unique value retrieved from the column LOGIN (SELECT clause) into the const char* variable pUsername. Im not sure of what function I should use for this. I hope you guys can help. Thanks a lot in advance!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const char* pUsername;
   std::string u;
   u = pUsername;
   std::string select = "SELECT DISTINCT LOGIN FROM USER_TABLE WHERE ID ='" + u + "';";
   SQLCHAR sql[1024];
   strcpy((char*) sql, select.c_str());
 
   SQLHANDLE handle; 
   SQLSMALLINT type; 
   SQLHENV env; 
   SQLHDBC dbc;
   SQLHSTMT stmt; 
   SQLRETURN ret; 
   SQLCHAR outstr[255]; 
   SQLSMALLINT outstrlen; 
   SQLCHAR conn[256] = 
    "DSN=ORACLE_DSN;UID=xxxxxxx;PWD=xxxxxxxx;";
 
   
   SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
   SQLSetEnvAttr (env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
   SQLAllocHandle (SQL_HANDLE_DBC, env, &dbc);
   ret = SQLDriverConnect(dbc, NULL, conn, SQL_NTS, outstr, sizeof (outstr), &outstrlen, SQL_DRIVER_NOPROMPT);
   
   if (SQL_SUCCEEDED(ret)) {
    SQLAllocHandle (SQL_HANDLE_STMT, dbc, &stmt);
    SQLExecDirect(stmt, sql, SQL_NTS);
    ret = SQLFetch(stmt);
    if (SQL_SUCCEEDED(ret))
    {
     
      //HELP HERE!!!     
      return (SecurityErrOK);
 
    } else 
    {
        return (SecurityErrNoSuchUser);
    }

 
   } else {
    return (SecurityErrNoSuchUser);
 }
Last edited on
Topic archived. No new replies allowed.