描述
注册一个可用于配置文件执行SQL语句的回调函数。
C / C ++语法
void *sqlite3_profile(sqlite3*, void(*xProfile)(void*,const char*,sqlite3_uint64), void*); |
PB语法
FUNCTION sqlite3_profile ( _ BYVAL hDbc AS DWORD, _ BYVAL pProfileCallback AS DWORD, _ BYVAL pData AS DWORD _ ) AS DWORD |
参数
hDbc
[in]连接句柄。
pProfileCallback
[in]指向回调函数的指针。
pData
[in]一个可选值,它被转发到每个回调调用的第一个参数。
返回值
先前注册的跟踪回调的pData参数。
备注
每个SQL语句完成后,将调用由sqlite3_profile注册的回调函数。配置文件回调包含原始语句文本以及该语句运行多长时间的挂钟时间的估计值。配置文件回调时间是以纳秒为单位,但是当前的实现只能够进行毫秒的分辨率,所以时间中的六个最低有效数字是无意义的。SQLite的未来版本可能会在分析器回调中提供更高的分辨率。sqlite3_profile函数被认为是实验性的,并且将来会在SQLite版本中发生更改
C ++实现代码
#ifndef SQLITE_OMIT_TRACE
/*
** Register a trace function. The pArg from the previously registered trace
** is returned.
**
** A NULL trace function means that no tracing is executeds. A non-NULL
** trace is a pointer to a function that is invoked at the start of each
** SQL statement.
*/
SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
void *pOld;
sqlite3_mutex_enter(db->mutex);
pOld = db->pTraceArg;
db->xTrace = xTrace;
db->pTraceArg = pArg;
sqlite3_mutex_leave(db->mutex);
return pOld;
}
/*
** Register a profile function. The pArg from the previously registered
** profile function is returned.
**
** A NULL profile function means that no profiling is executes. A non-NULL
** profile is a pointer to a function that is invoked at the conclusion of
** each SQL statement that is run.
*/
SQLITE_API void *sqlite3_profile(
sqlite3 *db,
void (*xProfile)(void*,const char*,sqlite_uint64),
void *pArg
){
void *pOld;
sqlite3_mutex_enter(db->mutex);
pOld = db->pProfileArg;
db->xProfile = xProfile;
db->pProfileArg = pArg;
sqlite3_mutex_leave(db->mutex);
return pOld;
}
#endif /* SQLITE_OMIT_TRACE */