@@ -1269,29 +1269,29 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
1269
1269
RETCODE rc ;
1270
1270
SQLSMALLINT sql_c_type ;
1271
1271
char * buf = NULL ;
1272
+ zend_long pv_row = 0 ;
1273
+ bool pv_row_is_null = true;
1274
+ zval * pv_res , tmp ;
1272
1275
#ifdef HAVE_SQL_EXTENDED_FETCH
1273
1276
SQLULEN crow ;
1274
1277
SQLUSMALLINT RowStatus [1 ];
1275
- SQLLEN rownum ;
1276
- zval * pv_res , tmp ;
1277
- zend_long pv_row = -1 ;
1278
+ #endif
1278
1279
1279
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "r|l" , & pv_res , & pv_row ) == FAILURE ) {
1280
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "r|l! " , & pv_res , & pv_row , & pv_row_is_null ) == FAILURE ) {
1280
1281
RETURN_THROWS ();
1281
1282
}
1282
1283
1283
- rownum = pv_row ;
1284
- #else
1285
- zval * pv_res , tmp ;
1286
-
1287
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "r" , & pv_res ) == FAILURE ) {
1284
+ if ((result = (odbc_result * )zend_fetch_resource (Z_RES_P (pv_res ), "ODBC result" , le_result )) == NULL ) {
1288
1285
RETURN_THROWS ();
1289
1286
}
1290
- #endif
1291
1287
1292
- if ((result = (odbc_result * )zend_fetch_resource (Z_RES_P (pv_res ), "ODBC result" , le_result )) == NULL ) {
1293
- RETURN_THROWS ();
1288
+ /* TODO deprecate $row argument values less than 1 after PHP 8.4 */
1289
+
1290
+ #ifndef HAVE_SQL_EXTENDED_FETCH
1291
+ if (!pv_row_is_null && pv_row > 0 ) {
1292
+ php_error_docref (NULL , E_WARNING , "Extended fetch functionality is not available, argument #3 ($row) is ignored" );
1294
1293
}
1294
+ #endif
1295
1295
1296
1296
if (result -> numcols == 0 ) {
1297
1297
php_error_docref (NULL , E_WARNING , "No tuples available at this result index" );
@@ -1300,8 +1300,8 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
1300
1300
1301
1301
#ifdef HAVE_SQL_EXTENDED_FETCH
1302
1302
if (result -> fetch_abs ) {
1303
- if (rownum > 0 ) {
1304
- rc = SQLExtendedFetch (result -> stmt ,SQL_FETCH_ABSOLUTE ,rownum ,& crow ,RowStatus );
1303
+ if (! pv_row_is_null && pv_row > 0 ) {
1304
+ rc = SQLExtendedFetch (result -> stmt ,SQL_FETCH_ABSOLUTE ,( SQLLEN ) pv_row ,& crow ,RowStatus );
1305
1305
} else {
1306
1306
rc = SQLExtendedFetch (result -> stmt ,SQL_FETCH_NEXT ,1 ,& crow ,RowStatus );
1307
1307
}
@@ -1316,8 +1316,8 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
1316
1316
array_init (return_value );
1317
1317
1318
1318
#ifdef HAVE_SQL_EXTENDED_FETCH
1319
- if (rownum > 0 && result -> fetch_abs )
1320
- result -> fetched = rownum ;
1319
+ if (! pv_row_is_null && pv_row > 0 && result -> fetch_abs )
1320
+ result -> fetched = ( SQLLEN ) pv_row ;
1321
1321
else
1322
1322
#endif
1323
1323
result -> fetched ++ ;
@@ -1430,28 +1430,28 @@ PHP_FUNCTION(odbc_fetch_into)
1430
1430
SQLSMALLINT sql_c_type ;
1431
1431
char * buf = NULL ;
1432
1432
zval * pv_res , * pv_res_arr , tmp ;
1433
- #ifdef HAVE_SQL_EXTENDED_FETCH
1434
1433
zend_long pv_row = 0 ;
1434
+ bool pv_row_is_null = true;
1435
+ #ifdef HAVE_SQL_EXTENDED_FETCH
1435
1436
SQLULEN crow ;
1436
1437
SQLUSMALLINT RowStatus [1 ];
1437
- SQLLEN rownum = -1 ;
1438
1438
#endif /* HAVE_SQL_EXTENDED_FETCH */
1439
1439
1440
- #ifdef HAVE_SQL_EXTENDED_FETCH
1441
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "rz|l" , & pv_res , & pv_res_arr , & pv_row ) == FAILURE ) {
1440
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "rz|l!" , & pv_res , & pv_res_arr , & pv_row , & pv_row_is_null ) == FAILURE ) {
1442
1441
RETURN_THROWS ();
1443
1442
}
1444
1443
1445
- rownum = pv_row ;
1446
- #else
1447
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "rz" , & pv_res , & pv_res_arr ) == FAILURE ) {
1444
+ if ((result = (odbc_result * )zend_fetch_resource (Z_RES_P (pv_res ), "ODBC result" , le_result )) == NULL ) {
1448
1445
RETURN_THROWS ();
1449
1446
}
1450
- #endif /* HAVE_SQL_EXTENDED_FETCH */
1451
1447
1452
- if ((result = (odbc_result * )zend_fetch_resource (Z_RES_P (pv_res ), "ODBC result" , le_result )) == NULL ) {
1453
- RETURN_THROWS ();
1448
+ /* TODO deprecate $row argument values less than 1 after PHP 8.4 */
1449
+
1450
+ #ifndef HAVE_SQL_EXTENDED_FETCH
1451
+ if (!pv_row_is_null && pv_row > 0 ) {
1452
+ php_error_docref (NULL , E_WARNING , "Extended fetch functionality is not available, argument #3 ($row) is ignored" );
1454
1453
}
1454
+ #endif
1455
1455
1456
1456
if (result -> numcols == 0 ) {
1457
1457
php_error_docref (NULL , E_WARNING , "No tuples available at this result index" );
@@ -1465,8 +1465,8 @@ PHP_FUNCTION(odbc_fetch_into)
1465
1465
1466
1466
#ifdef HAVE_SQL_EXTENDED_FETCH
1467
1467
if (result -> fetch_abs ) {
1468
- if (rownum > 0 ) {
1469
- rc = SQLExtendedFetch (result -> stmt ,SQL_FETCH_ABSOLUTE ,rownum ,& crow ,RowStatus );
1468
+ if (! pv_row_is_null && pv_row > 0 ) {
1469
+ rc = SQLExtendedFetch (result -> stmt ,SQL_FETCH_ABSOLUTE ,( SQLLEN ) pv_row ,& crow ,RowStatus );
1470
1470
} else {
1471
1471
rc = SQLExtendedFetch (result -> stmt ,SQL_FETCH_NEXT ,1 ,& crow ,RowStatus );
1472
1472
}
@@ -1479,8 +1479,8 @@ PHP_FUNCTION(odbc_fetch_into)
1479
1479
}
1480
1480
1481
1481
#ifdef HAVE_SQL_EXTENDED_FETCH
1482
- if (rownum > 0 && result -> fetch_abs )
1483
- result -> fetched = rownum ;
1482
+ if (! pv_row_is_null && pv_row > 0 && result -> fetch_abs )
1483
+ result -> fetched = ( SQLLEN ) pv_row ;
1484
1484
else
1485
1485
#endif
1486
1486
result -> fetched ++ ;
@@ -1560,8 +1560,8 @@ PHP_FUNCTION(odbc_fetch_row)
1560
1560
odbc_result * result ;
1561
1561
RETCODE rc ;
1562
1562
zval * pv_res ;
1563
- zend_long pv_row ;
1564
- bool pv_row_is_null = 1 ;
1563
+ zend_long pv_row = 0 ;
1564
+ bool pv_row_is_null = true ;
1565
1565
#ifdef HAVE_SQL_EXTENDED_FETCH
1566
1566
SQLULEN crow ;
1567
1567
SQLUSMALLINT RowStatus [1 ];
@@ -1575,6 +1575,17 @@ PHP_FUNCTION(odbc_fetch_row)
1575
1575
RETURN_THROWS ();
1576
1576
}
1577
1577
1578
+ #ifndef HAVE_SQL_EXTENDED_FETCH
1579
+ if (!pv_row_is_null ) {
1580
+ php_error_docref (NULL , E_WARNING , "Extended fetch functionality is not available, argument #3 ($row) is ignored" );
1581
+ }
1582
+ #else
1583
+ if (!pv_row_is_null && pv_row < 1 ) {
1584
+ php_error_docref (NULL , E_WARNING , "Argument #3 ($row) must be greater than or equal to 1" );
1585
+ RETURN_FALSE ;
1586
+ }
1587
+ #endif
1588
+
1578
1589
if (result -> numcols == 0 ) {
1579
1590
php_error_docref (NULL , E_WARNING , "No tuples available at this result index" );
1580
1591
RETURN_FALSE ;
@@ -1594,12 +1605,12 @@ PHP_FUNCTION(odbc_fetch_row)
1594
1605
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
1595
1606
RETURN_FALSE ;
1596
1607
}
1597
-
1608
+ #ifdef HAVE_SQL_EXTENDED_FETCH
1598
1609
if (!pv_row_is_null ) {
1599
1610
result -> fetched = (SQLLEN )pv_row ;
1600
- } else {
1611
+ } else
1612
+ #endif
1601
1613
result -> fetched ++ ;
1602
- }
1603
1614
1604
1615
RETURN_TRUE ;
1605
1616
}
0 commit comments