Skip to content

Commit b2bc9f3

Browse files
committed
Todo everything...
1 parent 072b19f commit b2bc9f3

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ext/pdo/pdo_dbh.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,12 @@ static zval *pdo_stmt_instantiate(pdo_dbh_t *dbh, zval *object, zend_class_entry
426426
{
427427
if (!Z_ISUNDEF_P(ctor_args)) {
428428
if (Z_TYPE_P(ctor_args) != IS_ARRAY) {
429+
/* TODO Always TypeError */
429430
pdo_raise_impl_error(dbh, NULL, "HY000", "constructor arguments must be passed as an array");
430431
return NULL;
431432
}
432433
if (!dbstmt_ce->constructor) {
434+
/* TODO Error? */
433435
pdo_raise_impl_error(dbh, NULL, "HY000", "user-supplied statement does not accept constructor arguments");
434436
return NULL;
435437
}
@@ -506,6 +508,7 @@ PHP_METHOD(PDO, prepare)
506508
|| Z_TYPE_P(item) != IS_STRING
507509
|| (pce = zend_lookup_class(Z_STR_P(item))) == NULL
508510
) {
511+
/* TODO Always TypeError */
509512
pdo_raise_impl_error(dbh, NULL, "HY000",
510513
"PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); "
511514
"the classname must be a string specifying an existing class"
@@ -515,19 +518,22 @@ PHP_METHOD(PDO, prepare)
515518
}
516519
dbstmt_ce = pce;
517520
if (!instanceof_function(dbstmt_ce, pdo_dbstmt_ce)) {
521+
/* TODO Always TypeError */
518522
pdo_raise_impl_error(dbh, NULL, "HY000",
519523
"user-supplied statement class must be derived from PDOStatement");
520524
PDO_HANDLE_DBH_ERR();
521525
RETURN_FALSE;
522526
}
523527
if (dbstmt_ce->constructor && !(dbstmt_ce->constructor->common.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED))) {
528+
/* TODO Always TError */
524529
pdo_raise_impl_error(dbh, NULL, "HY000",
525530
"user-supplied statement class cannot have a public constructor");
526531
PDO_HANDLE_DBH_ERR();
527532
RETURN_FALSE;
528533
}
529534
if ((item = zend_hash_index_find(Z_ARRVAL_P(opt), 1)) != NULL) {
530535
if (Z_TYPE_P(item) != IS_ARRAY) {
536+
/* TODO Always TypeError */
531537
pdo_raise_impl_error(dbh, NULL, "HY000",
532538
"PDO::ATTR_STATEMENT_CLASS requires format array(classname, ctor_args); "
533539
"ctor_args must be an array"
@@ -546,6 +552,7 @@ PHP_METHOD(PDO, prepare)
546552

547553
if (!pdo_stmt_instantiate(dbh, return_value, dbstmt_ce, &ctor_args)) {
548554
if (EXPECTED(!EG(exception))) {
555+
/* TODO Error? */
549556
pdo_raise_impl_error(dbh, NULL, "HY000",
550557
"failed to instantiate user-supplied statement class"
551558
);
@@ -679,6 +686,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
679686
{
680687
zend_long lval;
681688

689+
/* TODO Always TypeError (also restrict to actual integer?) */
682690
#define PDO_LONG_PARAM_CHECK \
683691
if (Z_TYPE_P(value) != IS_LONG && Z_TYPE_P(value) != IS_STRING && Z_TYPE_P(value) != IS_FALSE && Z_TYPE_P(value) != IS_TRUE) { \
684692
pdo_raise_impl_error(dbh, NULL, "HY000", "attribute value must be an integer"); \
@@ -697,6 +705,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
697705
dbh->error_mode = lval;
698706
return SUCCESS;
699707
default:
708+
/* TODO Always ValueError */
700709
pdo_raise_impl_error(dbh, NULL, "HY000", "invalid error mode");
701710
PDO_HANDLE_DBH_ERR();
702711
return FAILURE;
@@ -713,6 +722,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
713722
dbh->desired_case = lval;
714723
return SUCCESS;
715724
default:
725+
/* TODO Always ValueError */
716726
pdo_raise_impl_error(dbh, NULL, "HY000", "invalid case folding mode");
717727
PDO_HANDLE_DBH_ERR();
718728
return FAILURE;
@@ -729,6 +739,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
729739
zval *tmp;
730740
if ((tmp = zend_hash_index_find(Z_ARRVAL_P(value), 0)) != NULL && Z_TYPE_P(tmp) == IS_LONG) {
731741
if (Z_LVAL_P(tmp) == PDO_FETCH_INTO || Z_LVAL_P(tmp) == PDO_FETCH_CLASS) {
742+
/* TODO Always ValueError */
732743
pdo_raise_impl_error(dbh, NULL, "HY000", "FETCH_INTO and FETCH_CLASS are not yet supported as default fetch modes");
733744
return FAILURE;
734745
}
@@ -738,6 +749,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
738749
}
739750
lval = zval_get_long(value);
740751
if (lval == PDO_FETCH_USE_DEFAULT) {
752+
/* TODO Always ValueError */
741753
pdo_raise_impl_error(dbh, NULL, "HY000", "invalid fetch mode type");
742754
return FAILURE;
743755
}
@@ -766,6 +778,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
766778
|| Z_TYPE_P(item) != IS_STRING
767779
|| (pce = zend_lookup_class(Z_STR_P(item))) == NULL
768780
) {
781+
/* TODO Always TypeError */
769782
pdo_raise_impl_error(dbh, NULL, "HY000",
770783
"PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); "
771784
"the classname must be a string specifying an existing class"
@@ -774,12 +787,14 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
774787
return FAILURE;
775788
}
776789
if (!instanceof_function(pce, pdo_dbstmt_ce)) {
790+
/* TODO Always TypeError */
777791
pdo_raise_impl_error(dbh, NULL, "HY000",
778792
"user-supplied statement class must be derived from PDOStatement");
779793
PDO_HANDLE_DBH_ERR();
780794
return FAILURE;
781795
}
782796
if (pce->constructor && !(pce->constructor->common.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED))) {
797+
/* TODO Always TypeError */
783798
pdo_raise_impl_error(dbh, NULL, "HY000",
784799
"user-supplied statement class cannot have a public constructor");
785800
PDO_HANDLE_DBH_ERR();
@@ -792,6 +807,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
792807
}
793808
if ((item = zend_hash_index_find(Z_ARRVAL_P(value), 1)) != NULL) {
794809
if (Z_TYPE_P(item) != IS_ARRAY) {
810+
/* TODO Always TypeError */
795811
pdo_raise_impl_error(dbh, NULL, "HY000",
796812
"PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); "
797813
"ctor_args must be an array"
@@ -928,6 +944,7 @@ PHP_METHOD(PDO, exec)
928944
ZEND_PARSE_PARAMETERS_END();
929945

930946
if (!statement_len) {
947+
/* TODO ValueError */
931948
pdo_raise_impl_error(dbh, NULL, "HY000", "trying to execute an empty query");
932949
RETURN_FALSE;
933950
}

ext/pdo/pdo_sql_parser.re

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ PDO_API int pdo_parse_params(pdo_stmt_t *stmt, const char *inquery, size_t inque
151151
/* did the query make sense to me? */
152152
if (query_type == (PDO_PLACEHOLDER_NAMED|PDO_PLACEHOLDER_POSITIONAL)) {
153153
/* they mixed both types; punt */
154+
/* TODO Always Error */
154155
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "mixed named and positional parameters");
155156
ret = -1;
156157
goto clean_up;
@@ -192,6 +193,7 @@ PDO_API int pdo_parse_params(pdo_stmt_t *stmt, const char *inquery, size_t inque
192193
goto safe;
193194
}
194195
}
196+
/* TODO Error? */
195197
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "number of bound variables does not match number of tokens");
196198
ret = -1;
197199
goto clean_up;
@@ -222,6 +224,7 @@ safe:
222224
if (param == NULL) {
223225
/* parameter was not defined */
224226
ret = -1;
227+
/* TODO Error? */
225228
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined");
226229
goto clean_up;
227230
}
@@ -257,6 +260,7 @@ safe:
257260
zend_string_release_ex(buf, 0);
258261
}
259262
} else {
263+
/* TODO Always TypeError */
260264
pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource");
261265
ret = -1;
262266
goto clean_up;

0 commit comments

Comments
 (0)