@@ -39,16 +39,41 @@ static int pdo_sqlite_stmt_dtor(pdo_stmt_t *stmt)
3939 return 1 ;
4040}
4141
42+ static int pdo_sqlite_stmt_step (pdo_sqlite_stmt * S )
43+ {
44+ int return_code ;
45+ bool bailout = false;
46+
47+ S -> stepping = 1 ;
48+ zend_try {
49+ return_code = sqlite3_step (S -> stmt );
50+ } zend_catch {
51+ bailout = true;
52+ } zend_end_try ();
53+ S -> stepping = 0 ;
54+
55+ if (bailout ) {
56+ zend_bailout ();
57+ }
58+
59+ return return_code ;
60+ }
61+
4262static int pdo_sqlite_stmt_execute (pdo_stmt_t * stmt )
4363{
4464 pdo_sqlite_stmt * S = (pdo_sqlite_stmt * )stmt -> driver_data ;
4565
66+ if (S -> stepping ) {
67+ zend_throw_error (NULL , "Cannot execute a PDOStatement while it is executing" );
68+ return 0 ;
69+ }
70+
4671 if (stmt -> executed && !S -> done ) {
4772 sqlite3_reset (S -> stmt );
4873 }
4974
5075 S -> done = 0 ;
51- switch (sqlite3_step ( S -> stmt )) {
76+ switch (pdo_sqlite_stmt_step ( S )) {
5277 case SQLITE_ROW :
5378 S -> pre_fetched = 1 ;
5479 php_pdo_stmt_set_column_count (stmt , sqlite3_data_count (S -> stmt ));
@@ -80,6 +105,11 @@ static int pdo_sqlite_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_d
80105
81106 switch (event_type ) {
82107 case PDO_PARAM_EVT_EXEC_PRE :
108+ if (S -> stepping ) {
109+ zend_throw_error (NULL , "Cannot execute a PDOStatement while it is executing" );
110+ return 0 ;
111+ }
112+
83113 if (stmt -> executed && !S -> done ) {
84114 sqlite3_reset (S -> stmt );
85115 S -> done = 1 ;
@@ -214,7 +244,11 @@ static int pdo_sqlite_stmt_fetch(pdo_stmt_t *stmt,
214244 if (S -> done ) {
215245 return 0 ;
216246 }
217- i = sqlite3_step (S -> stmt );
247+ if (S -> stepping ) {
248+ zend_throw_error (NULL , "Cannot fetch from a PDOStatement while it is executing" );
249+ return 0 ;
250+ }
251+ i = pdo_sqlite_stmt_step (S );
218252 switch (i ) {
219253 case SQLITE_ROW :
220254 return 1 ;
@@ -363,6 +397,12 @@ static int pdo_sqlite_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *ret
363397static int pdo_sqlite_stmt_cursor_closer (pdo_stmt_t * stmt )
364398{
365399 pdo_sqlite_stmt * S = (pdo_sqlite_stmt * )stmt -> driver_data ;
400+
401+ if (S -> stepping ) {
402+ zend_throw_error (NULL , "Cannot close the cursor of a PDOStatement while it is executing" );
403+ return 0 ;
404+ }
405+
366406 sqlite3_reset (S -> stmt );
367407 return 1 ;
368408}
0 commit comments