Use a proper rcode for no more rows
[freeradius.git] / src / modules / rlm_sql / sql.c
index 76bf3da..51ba11d 100644 (file)
@@ -49,6 +49,7 @@ const FR_NAME_NUMBER sql_rcode_table[] = {
        { "server error",       RLM_SQL_ERROR           },
        { "query invalid",      RLM_SQL_QUERY_INVALID   },
        { "no connection",      RLM_SQL_RECONNECT       },
+       { "no more rows",       RLM_SQL_NO_MORE_ROWS    },
        { NULL, 0 }
 };
 
@@ -115,7 +116,7 @@ int sql_fr_pair_list_afrom_str(TALLOC_CTX *ctx, REQUEST *request, VALUE_PAIR **h
         *      Verify the 'Attribute' field
         */
        if (!row[2] || row[2][0] == '\0') {
-               REDEBUG("The 'Attribute' field is empty or NULL, skipping the entire row");
+               REDEBUG("Attribute field is empty or NULL, skipping the entire row");
                return -1;
        }
 
@@ -135,14 +136,20 @@ int sql_fr_pair_list_afrom_str(TALLOC_CTX *ctx, REQUEST *request, VALUE_PAIR **h
                 *  Complain about empty or invalid 'op' field
                 */
                op = T_OP_CMP_EQ;
-               REDEBUG("The 'op' field for attribute '%s = %s' is NULL, or non-existent.", row[2], row[3]);
+               REDEBUG("The op field for attribute '%s = %s' is NULL, or non-existent.", row[2], row[3]);
                REDEBUG("You MUST FIX THIS if you want the configuration to behave as you expect");
        }
 
        /*
         *      The 'Value' field may be empty or NULL
         */
+       if (!row[3]) {
+               REDEBUG("Value field is empty or NULL, skipping the entire row");
+               return -1;
+       }
+
        value = row[3];
+
        /*
         *      If we have a new-style quoted string, where the
         *      *entire* string is quoted, do xlat's.
@@ -165,9 +172,9 @@ int sql_fr_pair_list_afrom_str(TALLOC_CTX *ctx, REQUEST *request, VALUE_PAIR **h
                 *      Mark the pair to be allocated later.
                 */
                case T_BACK_QUOTED_STRING:
-                       value = NULL;
                        do_xlat = 1;
-                       break;
+
+                       /* FALL-THROUGH */
 
                /*
                 *      Keep the original string.
@@ -483,7 +490,7 @@ int sql_getvpdata(TALLOC_CTX *ctx, rlm_sql_t *inst, REQUEST *request, rlm_sql_ha
        rcode = rlm_sql_select_query(inst, request, handle, query);
        if (rcode != RLM_SQL_OK) return -1; /* error handled by rlm_sql_select_query */
 
-       while (rlm_sql_fetch_row(inst, request, handle) == 0) {
+       while (rlm_sql_fetch_row(inst, request, handle) == RLM_SQL_OK) {
                row = (*handle)->row;
                if (!row) break;
                if (sql_fr_pair_list_afrom_str(ctx, request, pair, row) != 0) {