//---------------------------------------------------------------------------------------------------------------------------------
// File: core_stmt.cpp
//
// Contents: Core routines that use statement handles shared between sqlsrv and pdo_sqlsrv
//
// Copyright Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//---------------------------------------------------------------------------------------------------------------------------------
#include "core_sqlsrv.h"
namespace {
// certain drivers using this layer will call for repeated or out of order field retrievals. To allow this, we cache the
// results of every field request, and if it is out of order, we cache those for preceding fields.
struct field_cache {
void* value;
SQLLEN len;
sqlsrv_phptype type;
field_cache( void* field_value, SQLLEN field_len, sqlsrv_phptype t )
: type( t )
{
// if the value is NULL, then just record a NULL pointer
if( field_value != NULL ) {
value = sqlsrv_malloc( field_len );
memcpy( value, field_value, field_len );
len = field_len;
}
else {
value = NULL;
len = 0;
}
}
// no destructor because we don't want to release the memory when it goes out of scope, but instead we
// rely on the hash table destructor to free the memory
};
const int INITIAL_FIELD_STRING_LEN = 256; // base allocation size when retrieving a string field
// UTF-8 tags for byte length of characters, used by streams to make sure we don't clip a character in between reads
const unsigned int UTF8_MIDBYTE_MASK = 0xc0;
const unsigned int UTF8_MIDBYTE_TAG = 0x80;
const unsigned int UTF8_2BYTESEQ_TAG1 = 0xc0;
const unsigned int UTF8_2BYTESEQ_TAG2 = 0xd0;
const unsigned int UTF8_3BYTESEQ_TAG = 0xe0;
const unsigned int UTF8_4BYTESEQ_TAG = 0xf0;
const unsigned int UTF8_NBYTESEQ_MASK = 0xf0;
// constants used to convert from a DateTime object to a string which is sent to the server.
// Using the format defined by the ODBC documentation at http://msdn2.microsoft.com/en-us/library/ms712387(VS.85).aspx
namespace DateTime {
const char DATETIME_CLASS_NAME[] = "DateTime";
const size_t DATETIME_CLASS_NAME_LEN = sizeof( DATETIME_CLASS_NAME ) - 1;
const char DATETIMEOFFSET_FORMAT[] = "Y-m-d H:i:s.u P";
const size_t DATETIMEOFFSET_FORMAT_LEN = sizeof( DATETIMEOFFSET_FORMAT );
const char DATETIME_FORMAT[] = "Y-m-d H:i:s.u";
const size_t DATETIME_FORMAT_LEN = sizeof( DATETIME_FORMAT );
const char DATE_FORMAT[] = "Y-m-d";
const size_t DATE_FORMAT_LEN = sizeof( DATE_FORMAT );
}
// *** internal functions ***
// Only declarations are put here. Functions contain the documentation they need at their definition sites.
void calc_string_size( sqlsrv_stmt* stmt, SQLUSMALLINT field_index, SQLLEN sql_type, __out SQLLEN& size TSRMLS_DC );
size_t calc_utf8_missing( sqlsrv_stmt* stmt, const char* buffer, size_t buffer_end TSRMLS_DC );
bool check_for_next_stream_parameter( sqlsrv_stmt* stmt TSRMLS_DC );
bool convert_input_param_to_utf16( zval* input_param_z, zval* convert_param_z );
void core_get_field_common( __inout sqlsrv_stmt* stmt, SQLUSMALLINT field_index, sqlsrv_phptype
sqlsrv_php_type, __out void** field_value, __out SQLLEN* field_len TSRMLS_DC );
// returns the ODBC C type constant that matches the PHP type and encoding given
SQLSMALLINT default_c_type( sqlsrv_stmt* stmt, unsigned int paramno, zval const* param_z, SQLSRV_ENCODING encoding TSRMLS_DC );
void default_sql_size_and_scale( sqlsrv_stmt* stmt, unsigned int paramno, zval* param_z, SQLSRV_ENCODING encoding,
__out SQLULEN& column_size, __out SQLSMALLINT& decimal_digits TSRMLS_DC );
// given a zval and encoding, determine the appropriate sql type, column size, and decimal scale (if appropriate)
void default_sql_type( sqlsrv_stmt* stmt, unsigned int paramno, zval* param_z, SQLSRV_ENCODING encoding,
__out SQLSMALLINT& sql_type TSRMLS_DC );
void field_cache_dtor( void* data );
void finalize_output_parameters( sqlsrv_stmt* stmt TSRMLS_DC );
void get_field_as_string( sqlsrv_stmt* stmt, SQLUSMALLINT field_index, sqlsrv_phptype sqlsrv_php_type,
__out void** field_value, __out SQLLEN* field_len TSRMLS_DC );
stmt_option const* get_stmt_option( sqlsrv_conn const* conn, unsigned long key, const stmt_option stmt_opts[] TSRMLS_DC );
bool is_valid_sqlsrv_phptype( sqlsrv_phptype type );
// assure there is enough space for the output parameter string
void resize_output_buffer_if_necessary( sqlsrv_stmt* stmt, zval* param_z, unsigned int paramno, SQLSRV_ENCODING encoding,
SQLSMALLINT c_type, SQLSMALLINT sql_type, SQLULEN column_size, SQLPOINTER& buffer,
SQLLEN& buffer_len TSRMLS_DC );
void save_output_param_for_later( sqlsrv_stmt* stmt, sqlsrv_output_param& param TSRMLS_DC );
// send all the stream data
void send_param_streams( sqlsrv_stmt* stmt TSRMLS_DC );
// called when a bound output string parameter is to be destroyed
void sqlsrv_output_param_dtor( void* data );
// called when a bound stream parameter is to be destroyed.
void sqlsrv_stream_dtor( void* data );
bool is_streamable_type( SQLINTEGER sql_type );
}
// constructor for sqlsrv_stmt. Here so that we can use functions declared earlier.
sqlsrv_stmt::sqlsrv_stmt( sqlsrv_conn* c, SQLHANDLE handle, error_callback e, void* drv TSRMLS_DC ) :
sqlsrv_context( handle, SQL_HANDLE_STMT, e, drv, SQLSRV_ENCODING_DEFAULT ),
conn( c ),
executed( false ),
past_fetch_end( false ),
current_results( NULL ),
cursor_type( SQL_CURSOR_FORWARD_ONLY ),
has_rows( false ),
fetch_called( false ),
last_field_index( -1 ),
past_next_result_end( false ),
param_ind_ptrs( 10 ), // initially hold 10 elements, which should cover 90% of the cases and only take < 100 byte
send_streams_at_exec( true ),
current_stream( NULL, SQLSRV_ENCODING_DEFAULT ),
current_stream_read( 0 ),
query_timeout( QUERY_TIMEOUT_INVALID ),
buffered_query_limit( sqlsrv_buffered_result_set::BUFFERED_QUERY_LIMIT_INVALID ),
active_stream( NULL )
{
// initialize the input string parameters array (which holds zvals)
MAKE_STD_ZVAL( param_input_strings );
core::sqlsrv_array_init( *conn, param_input_strings TSRMLS_CC );
// initialize the (input only) stream parameters (which holds sqlsrv_stream structures)
MAKE_STD_ZVAL( param_streams );
Z_TYPE_P( param_streams ) = IS_ARRAY;
ALLOC_HASHTABLE( Z_ARRVAL_P( param_streams ));
core::sqlsrv_zend_hash_init( *conn, Z_ARRVAL_P( param_streams ), 5 /* # of buckets */, NULL /*hashfn*/,
sqlsrv_stream_dtor, 0 /*persistent*/ TSRMLS_CC );
// initialize the (input only) datetime parameters of converted date time objects to strings
MAKE_STD_ZVAL( param_datetime_buffers );
array_init( param_datetime_buffers );
// initialize the output string parameters (which holds sqlsrv_output_param structures)
MAKE_STD_ZVAL( output_params );
Z_TYPE_P( output_params ) = IS_ARRAY;
ALLOC_HASHTABLE( Z_ARRVAL_P( output_params ));
core::sqlsrv_zend_hash_init( *conn, Z_ARRVAL_P( output_params ), 5 /* #
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
sqlsrv_非官方_3.0.2.2%28支持32、64位php%29.zip (51个子文件)
php_sqlsrv_54_nts.dll 144KB
php_pdo_sqlsrv_55_nts.dll 144KB
php_pdo_sqlsrv_56_nts.dll 144KB
php_pdo_sqlsrv_53_nts.dll 131KB
php_pdo_sqlsrv_56_ts.dll 146KB
x64
php_pdo_sqlsrv_55_nts.dll 186KB
php_pdo_sqlsrv_56_nts.dll 186KB
php_pdo_sqlsrv_56_ts.dll 189KB
php_sqlsrv_56_ts.dll 214KB
php_pdo_sqlsrv_55_ts.dll 189KB
php_sqlsrv_55_ts.dll 213KB
php_sqlsrv_55_nts.dll 207KB
php_sqlsrv_56_nts.dll 207KB
php_sqlsrv_56_ts.dll 160KB
php_pdo_sqlsrv_55_ts.dll 146KB
php_sqlsrv_55_ts.dll 160KB
php_sqlsrv_55_nts.dll 157KB
php_pdo_sqlsrv_54_nts.dll 132KB
php_sqlsrv_56_nts.dll 157KB
php_sqlsrv_53_ts.dll 147KB
php_pdo_sqlsrv_53_ts.dll 134KB
php_pdo_sqlsrv_54_ts.dll 134KB
php_sqlsrv_54_ts.dll 147KB
source code
sqlsrv
core_stmt.cpp 104KB
conn.cpp 49KB
version.h 1KB
core_results.cpp 54KB
php_sqlsrv.h 24KB
util.cpp 34KB
core_util.cpp 13KB
init.cpp 28KB
core_stream.cpp 9KB
core_init.cpp 7KB
core_conn.cpp 30KB
core_sqlsrv.h 86KB
stmt.cpp 82KB
pdo_sqlsrv
core_stmt.cpp 104KB
version.h 1KB
core_results.cpp 54KB
pdo_util.cpp 26KB
pdo_parser.cpp 12KB
core_util.cpp 13KB
pdo_stmt.cpp 50KB
pdo_init.cpp 14KB
core_stream.cpp 9KB
pdo_sqlsrv.h 15KB
core_init.cpp 7KB
core_conn.cpp 30KB
core_sqlsrv.h 86KB
pdo_dbh.cpp 51KB
php_sqlsrv_53_nts.dll 144KB
共 51 条
- 1
资源评论
- rjhzp1432020-04-16不错,一换立马可以连接了。
一一先生
- 粉丝: 1
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功