Skip to content

Commit 814e22c

Browse files
committed
Solved some issues with the dbd api
1 parent 1bb2170 commit 814e22c

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

src/dbconns.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int mod_okioki_execute_view(request_rec *http_request, mod_okioki_dir_config *cf
3535
int have_result = (view->link_cmd == M_POST) | (view->link_cmd == M_GET);
3636
char *arg;
3737
int argc = view->nr_sql_params;
38-
char *argv[argc];
38+
char *argv[argc + 1];
3939
off_t i;
4040
const char *db_value;
4141
char *value;
@@ -56,59 +56,86 @@ int mod_okioki_execute_view(request_rec *http_request, mod_okioki_dir_config *cf
5656

5757
argv[i] = arg;
5858
}
59+
argv[i] = NULL;
60+
61+
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, pool, "[mod_okioki] test 1.");
5962

6063
// Retrieve a database connection from the resource pool.
6164
HTTP_ASSERT_NOT_NULL(
6265
db_conn = ap_dbd_acquire(http_request),
6366
HTTP_BAD_GATEWAY, "[mod_okioki] Can not get database connection."
6467
)
6568

69+
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, pool, "[mod_okioki] test 2.");
70+
6671
// Get the prepared statement.
6772
HTTP_ASSERT_NOT_NULL(
6873
db_statement = apr_hash_get(db_conn->prepared, view->sql, view->sql_len),
6974
HTTP_NOT_FOUND, "[mod_okioki] Can not find '%s'", view->sql
7075
)
7176

77+
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, pool, "[mod_okioki] test 3 argc:%i first='%s'.", argc, argv[0]);
78+
7279
// Execute the statement.
7380
if (have_result) {
81+
db_result = NULL;
7482
HTTP_ASSERT_ZERO(
75-
apr_dbd_pselect(db_conn->driver, pool, db_conn->handle, &db_result, db_statement, 1, argc, (const char **)argv),
83+
apr_dbd_pselect(db_conn->driver, db_conn->pool, db_conn->handle, &db_result, db_statement, 1, argc, (const char **)argv),
7684
HTTP_INTERNAL_SERVER_ERROR, "[mod_okioki] Can not execute select statement."
7785
)
86+
HTTP_ASSERT_NOT_NULL(
87+
db_result,
88+
HTTP_INTERNAL_SERVER_ERROR, "[mod_okioki] Result was not set by apr_dbd_pselect."
89+
)
90+
7891
nr_rows = apr_dbd_num_tuples(db_conn->driver, db_result);
92+
//nr_rows = 0;
7993
} else {
8094
HTTP_ASSERT_ZERO(
81-
apr_dbd_pquery(db_conn->driver, pool, db_conn->handle, &nr_rows, db_statement, argc, (const char **)argv),
95+
apr_dbd_pquery(db_conn->driver, db_conn->pool, db_conn->handle, &nr_rows, db_statement, argc, (const char **)argv),
8296
HTTP_INTERNAL_SERVER_ERROR, "[mod_okioki] Can not execute query."
8397
)
8498
}
8599

100+
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, pool, "[mod_okioki] test 4.");
101+
86102
if (nr_rows < 1) {
87103
return HTTP_NOT_FOUND;
88104
}
89105

106+
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, pool, "[mod_okioki] test 5.");
107+
90108
if (have_result) {
91109
nr_cols = apr_dbd_num_cols(db_conn->driver, db_result);
92110
for (row_nr = 0; row_nr < nr_rows; row_nr++) {
111+
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, pool, "[mod_okioki] test 6.");
112+
93113
// Create a new hash table row.
94114
HTTP_ASSERT_NOT_NULL(
95115
row = apr_hash_make(pool),
96116
HTTP_INTERNAL_SERVER_ERROR, "[mod_okioki] Can not allocate hash table for row."
97117
)
98118

119+
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, pool, "[mod_okioki] test 7.");
120+
99121
// Add the empty row to the result, we fill in the row afterwards.
100122
HTTP_ASSERT_NOT_NULL(
101123
row_item = (apr_hash_t **)apr_array_push(result),
102124
HTTP_INTERNAL_SERVER_ERROR, "[mod_okioki] Failed to add row to result."
103125
)
104126
*row_item = row;
105127

128+
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, pool, "[mod_okioki] test 8.");
129+
106130
// Retrieve a row from the result.
131+
db_row = NULL;
107132
HTTP_ASSERT_ZERO(
108-
apr_dbd_get_row(db_conn->driver, pool, db_result, &db_row, row_nr),
133+
apr_dbd_get_row(db_conn->driver, pool, db_result, &db_row, row_nr + 1),
109134
HTTP_BAD_GATEWAY, "[mod_okioki] Failed to retrieve row from select."
110135
)
111136

137+
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, pool, "[mod_okioki] test 9.");
138+
112139
// Add the columns to the row.
113140
for (col_nr = 0; col_nr < nr_cols; col_nr++) {
114141
// Get the value from the database.
@@ -126,9 +153,13 @@ int mod_okioki_execute_view(request_rec *http_request, mod_okioki_dir_config *cf
126153
// Add value to resul.t
127154
apr_hash_set(row, apr_dbd_get_name(db_conn->driver, db_result, col_nr), APR_HASH_KEY_STRING, value);
128155
}
156+
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, pool, "[mod_okioki] test 10.");
157+
129158
}
130159
}
131160

161+
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, pool, "[mod_okioki] test 11.");
162+
132163
return HTTP_OK;
133164
}
134165

0 commit comments

Comments
 (0)