Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions ext/pdo_odbc/odbc_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p
pdo_odbc_stmt *S = (pdo_odbc_stmt*)stmt->driver_data;
RETCODE rc;
SWORD sqltype = 0, ctype = 0, scale = 0, nullable = 0;
UDWORD precision = 0;
SQLULEN precision = 0;
pdo_odbc_param *P;

/* we're only interested in parameters for prepared SQL right now */
Expand Down Expand Up @@ -315,17 +315,33 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p

rc = SQLDescribeParam(S->stmt, (SQLUSMALLINT) param->paramno+1, &sqltype, &precision, &scale, &nullable);
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
/* MS Access, for instance, doesn't support SQLDescribeParam,
* so we need to guess */
sqltype = PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB ?
SQL_LONGVARBINARY :
SQL_LONGVARCHAR;
precision = 4000;
scale = 5;
nullable = 1;

if (param->max_value_len > 0) {
precision = param->max_value_len;
/* if the PDO_PARAM_TYPE is string, lets see if we can fit it in a varchar. */
if ((Z_TYPE_P(param->parameter) != IS_ARRAY &&
Z_TYPE_P(param->parameter) != IS_OBJECT &&
Z_TYPE_P(param->parameter) != IS_RESOURCE) &&
param->max_value_len <= 0 &&
(Z_STRLEN_P(param->parameter) < 4000 ||
Z_TYPE_P(param->parameter) != IS_STRING)) {
sqltype = SQL_VARCHAR;
if(Z_TYPE_P(param->parameter) == IS_STRING) {
precision = Z_STRLEN_P(param->parameter);
} else {
precision = 10;
}
scale = 0;
} else {
/* MS Access, for instance, doesn't support SQLDescribeParam,
* so we need to guess */
sqltype = PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_LOB ?
SQL_LONGVARBINARY :
SQL_LONGVARCHAR;
precision = 4000;
scale = 5;
nullable = 1;

if (param->max_value_len > 0) {
precision = param->max_value_len;
}
}
}
if (sqltype == SQL_BINARY || sqltype == SQL_VARBINARY || sqltype == SQL_LONGVARBINARY) {
Expand Down Expand Up @@ -843,4 +859,4 @@ struct pdo_stmt_methods odbc_stmt_methods = {
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
*/