@@ -1703,6 +1703,9 @@ myodbc_remove_escape(MYSQL *mysql,char *name)
17031703
17041704/******************* Declarations ***********************************/
17051705
1706+ /* Default number of rows fetched per one COM_FETCH command. */
1707+
1708+ #define DEFAULT_PREFETCH_ROWS 1UL
17061709
17071710/*
17081711 These functions are called by function pointer MYSQL_STMT::read_row_func.
@@ -1728,6 +1731,7 @@ static my_bool setup_one_fetch_function(MYSQL_BIND *bind, MYSQL_FIELD *field);
17281731
17291732#define RESET_SERVER_SIDE 1
17301733#define RESET_LONG_DATA 2
1734+ #define RESET_STORE_RESULT 4
17311735
17321736static my_bool reset_stmt_handle (MYSQL_STMT * stmt , uint flags );
17331737
@@ -1968,6 +1972,7 @@ mysql_stmt_init(MYSQL *mysql)
19681972 stmt -> state = MYSQL_STMT_INIT_DONE ;
19691973 stmt -> mysql = mysql ;
19701974 stmt -> read_row_func = stmt_read_row_no_data ;
1975+ stmt -> prefetch_rows = DEFAULT_PREFETCH_ROWS ;
19711976 /* The rest of statement members was bzeroed inside malloc */
19721977
19731978 DBUG_RETURN (stmt );
@@ -2026,7 +2031,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length)
20262031 /* This is second prepare with another statement */
20272032 char buff [MYSQL_STMT_HEADER ]; /* 4 bytes - stmt id */
20282033
2029- if (reset_stmt_handle (stmt , RESET_LONG_DATA ))
2034+ if (reset_stmt_handle (stmt , RESET_LONG_DATA | RESET_STORE_RESULT ))
20302035 DBUG_RETURN (1 );
20312036 /*
20322037 These members must be reset for API to
@@ -2681,7 +2686,7 @@ stmt_read_row_from_cursor(MYSQL_STMT *stmt, unsigned char **row)
26812686 result -> rows = 0 ;
26822687 /* Send row request to the server */
26832688 int4store (buff , stmt -> stmt_id );
2684- int4store (buff + 4 , 1 ); /* number of rows to fetch */
2689+ int4store (buff + 4 , stmt -> prefetch_rows ); /* number of rows to fetch */
26852690 if (cli_advanced_command (mysql , COM_FETCH , buff , sizeof (buff ),
26862691 NullS , 0 , 1 ))
26872692 {
@@ -2739,12 +2744,29 @@ my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt,
27392744 stmt -> update_max_length = value ? * (const my_bool * ) value : 0 ;
27402745 break ;
27412746 case STMT_ATTR_CURSOR_TYPE :
2742- stmt -> flags = value ? * (const unsigned long * ) value : 0 ;
2747+ {
2748+ ulong cursor_type ;
2749+ cursor_type = value ? * (ulong * ) value : 0UL ;
2750+ if (cursor_type > (ulong ) CURSOR_TYPE_READ_ONLY )
2751+ goto err_not_implemented ;
2752+ stmt -> flags = cursor_type ;
2753+ break ;
2754+ }
2755+ case STMT_ATTR_PREFETCH_ROWS :
2756+ {
2757+ ulong prefetch_rows = value ? * (ulong * ) value : DEFAULT_PREFETCH_ROWS ;
2758+ if (value == 0 )
2759+ return TRUE;
2760+ stmt -> prefetch_rows = prefetch_rows ;
27432761 break ;
2762+ }
27442763 default :
2745- return TRUE ;
2764+ goto err_not_implemented ;
27462765 }
27472766 return FALSE;
2767+ err_not_implemented :
2768+ set_stmt_error (stmt , CR_NOT_IMPLEMENTED , unknown_sqlstate );
2769+ return TRUE;
27482770}
27492771
27502772
@@ -2821,7 +2843,7 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt)
28212843 DBUG_RETURN (1 );
28222844 }
28232845
2824- if (reset_stmt_handle (stmt , 0 ))
2846+ if (reset_stmt_handle (stmt , RESET_STORE_RESULT ))
28252847 DBUG_RETURN (1 );
28262848 /*
28272849 No need to check for stmt->state: if the statement wasn't
@@ -4826,7 +4848,11 @@ static my_bool reset_stmt_handle(MYSQL_STMT *stmt, uint flags)
48264848 MYSQL_DATA * result = & stmt -> result ;
48274849 my_bool has_cursor = stmt -> read_row_func == stmt_read_row_from_cursor ;
48284850
4829- if (result -> data )
4851+ /*
4852+ Reset stored result set if so was requested or it's a part
4853+ of cursor fetch.
4854+ */
4855+ if (result -> data && (has_cursor || (flags & RESET_STORE_RESULT )))
48304856 {
48314857 /* Result buffered */
48324858 free_root (& result -> alloc , MYF (MY_KEEP_PREALLOC ));
@@ -4885,7 +4911,7 @@ my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt)
48854911 DBUG_ENTER ("mysql_stmt_free_result" );
48864912
48874913 /* Free the client side and close the server side cursor if there is one */
4888- DBUG_RETURN (reset_stmt_handle (stmt , RESET_LONG_DATA ));
4914+ DBUG_RETURN (reset_stmt_handle (stmt , RESET_LONG_DATA | RESET_STORE_RESULT ));
48894915}
48904916
48914917/********************************************************************
0 commit comments