@@ -2010,6 +2010,75 @@ static void sqlite3result_clear_column_names_cache(php_sqlite3_result *result) {
20102010 result -> column_count = -1 ;
20112011}
20122012
2013+ PHP_METHOD (SQLite3Result , fetchAll )
2014+ {
2015+ int i ;
2016+ bool done = false;
2017+ php_sqlite3_result * result_obj ;
2018+ zval * object = ZEND_THIS ;
2019+ zend_long mode = PHP_SQLITE3_BOTH ;
2020+ result_obj = Z_SQLITE3_RESULT_P (object );
2021+
2022+ ZEND_PARSE_PARAMETERS_START (0 , 1 )
2023+ Z_PARAM_OPTIONAL
2024+ Z_PARAM_LONG (mode )
2025+ ZEND_PARSE_PARAMETERS_END ();
2026+
2027+ SQLITE3_CHECK_INITIALIZED (result_obj -> db_obj , result_obj -> stmt_obj -> initialised , SQLite3Result )
2028+
2029+ result_obj -> column_count = sqlite3_column_count (result_obj -> stmt_obj -> stmt );
2030+ if (mode & PHP_SQLITE3_ASSOC ) {
2031+ result_obj -> column_names = emalloc (result_obj -> column_count * sizeof (zend_string * ));
2032+
2033+ for (i = 0 ; i < result_obj -> column_count ; i ++ ) {
2034+ const char * column = sqlite3_column_name (result_obj -> stmt_obj -> stmt , i );
2035+ result_obj -> column_names [i ] = zend_string_init (column , strlen (column ), 0 );
2036+ }
2037+ }
2038+ array_init (return_value );
2039+
2040+ while (!done ) {
2041+ int step = sqlite3_step (result_obj -> stmt_obj -> stmt );
2042+
2043+ switch (step ) {
2044+ case SQLITE_ROW : {
2045+ zval result ;
2046+ array_init_size (& result , result_obj -> column_count );
2047+
2048+ for (i = 0 ; i < result_obj -> column_count ; i ++ ) {
2049+ zval data ;
2050+ sqlite_value_to_zval (result_obj -> stmt_obj -> stmt , i , & data );
2051+
2052+ if (mode & PHP_SQLITE3_NUM ) {
2053+ add_index_zval (& result , i , & data );
2054+ }
2055+
2056+ if (mode & PHP_SQLITE3_ASSOC ) {
2057+ if (mode & PHP_SQLITE3_NUM ) {
2058+ if (Z_REFCOUNTED (data )) {
2059+ Z_ADDREF (data );
2060+ }
2061+ }
2062+ zend_symtable_update (Z_ARR_P (& result ), result_obj -> column_names [i ], & data );
2063+ }
2064+ }
2065+
2066+ add_next_index_zval (return_value , & result );
2067+ break ;
2068+ }
2069+ case SQLITE_DONE :
2070+ done = true;
2071+ break ;
2072+ default :
2073+ if (!EG (exception )) {
2074+ php_sqlite3_error (result_obj -> db_obj , sqlite3_errcode (sqlite3_db_handle (result_obj -> stmt_obj -> stmt )), "Unable to execute statement: %s" , sqlite3_errmsg (sqlite3_db_handle (result_obj -> stmt_obj -> stmt )));
2075+ }
2076+ zval_ptr_dtor (return_value );
2077+ RETURN_FALSE ;
2078+ }
2079+ }
2080+ }
2081+
20132082/* {{{ Resets the result set back to the first row. */
20142083PHP_METHOD (SQLite3Result , reset )
20152084{
0 commit comments