+ int numfields = 0;
+ int i=0;
+ char **row=NULL;
+ SQLINTEGER len=0;
+
+ if(sql_query(inst, socket, querystr) < 0) {
+ return -1;
+ }
+
+ numfields = sql_num_fields(socket);
+
+ if( (row = (char **)malloc(sizeof(char *) * numfields)) == NULL) {
+ radlog(L_ERR, "sql_select_query: Out of memory!");
+ return -1;
+ }
+ memset(row, 0, (sizeof(char *) * (numfields)));
+ row[numfields-1] = NULL;
+
+ for(i=1; i<=numfields; i++) {
+ SQLColAttributes(socket->stmt_handle, ((SQLUSMALLINT) i), SQL_COLUMN_LENGTH,
+ NULL, 0, NULL, &len);
+ len++;
+
+ /*
+ * Allocate space for each column
+ */
+ row[i-1] = (SQLCHAR*)malloc((int)len);
+
+ /*
+ * This makes me feel dirty, but, according to Microsoft, it works.
+ * Any ODBC datatype can be converted to a 'char *' according to
+ * the following:
+ *
+ * http://msdn.microsoft.com/library/psdk/dasdk/odap4o4z.htm
+ */
+ SQLBindCol(socket->stmt_handle, i, SQL_C_CHAR, (SQLCHAR *)row[i-1], len, 0);
+ }
+
+ socket->row = row;
+