独孤求败的风格, 上代码:

/**

* Prepare statement loading from Config

* The ctime on dabase instance config could be used to control the expire * of all prepared statments

* Config ctime = now() could be used to force recompile for each bootstrap,

* date +%s could get the value of current seconds from EPOCH

* stmts will be name => query pairs

* Expired will be recompile automatically, any update on config should update ctime as well

*

* @author Anthony.chen

* 2010-2012 reserved

*/

class PSTMT{

public static $instances = array();

/**

* Loading the prepare statment from DB Connection

* The stmts is config linked to DB instance with 'stmts' k=>v array

*

* @return Boolean

*/

public static function prepare($db='default'){

//Getting statment from config

$_config = Pexcel::config('database')->$db;

$_ctime = Arr::get($_config,'ctime',0);

$_configStmts = Arr::get($_config,'stmts',NULL);

if($_configStmts != NULL){//There is statments configured

if(!isset(self::$instances[$db])){

$_sql = 'select name , EXTRACT(EPOCH FROM prepare_time) as ctime from pg_prepared_statements';

$_pstmts = DB::query(DB::SELECT,$_sql,true)->execute($db)->as_array();

if(!$_pstmts){

self::$instances[$db] = array();

}else{

//Log::debug('Before Commpiling,statement Found');

foreach($_pstmts as $_pstmt){

self::$instances[$db][$_pstmt->name] = $_pstmt->ctime;

}

}

}

//Compile the statments

foreach($_configStmts as $stmtName => $stmtQuery){

if(isset(self::$instances[$db][$stmtName])){

if( self::$instances[$db][$stmtName] < $_ctime){

//Log::debug($stmtName.' Expires');

}else{

//Log::debug($stmtName.' Exists');

continue;

}

}

self::compile($stmtName,$stmtQuery,$db);

}

}else{

throw new Error_Exception('stmts not in config!');

}

return True;

}

/**

* Compile the prepared statment

*

* @param String $stmtName, Statement name

* @param String $stmtQuery, Statement query

* @param String $db ,Instance name of database

*

* @return Boolean

*/

public static function compile($stmtName, $stmtQuery,$db ='default'){

if(isset(self::$instances[$db][$stmtName])){ //already Compiled

//Doing Nothing

//Log::debug('DEALLOCATE '.$stmtName);

DB::query(DB::UPDATE,'DEALLOCATE '.$stmtName)->execute($db);

}

$_ret = DB::query(DB::SELECT,$stmtQuery,False,NULL,$stmtName)->execute($db)->count();

//Log::debug(__FUNCTION__.':compiling the pstat:'.$stmtQuery);

self::$instances[$db][$stmtName] = time();

return True;

}

/**

* Execute the prepared statement

*

* @param String $stmtName, Statement Name

* @param Array $params , The parameter to be transfered into query

* @param Boolean $as_object, True to fetch result as object

* @param String $db, Database Instance name

*

* @return Array of result set

*/

public static function execute($stmtName,$params = array(),$as_object = TRUE,$db = 'default'){

if(isset(self::$instances[$db][$stmtName])){

return DB::query(DB::SELECT,NULL,$as_object,$params,$stmtName)->execute($db);

}else{

$_config = Pexcel::config('database')->$db;

$_configStmts = Arr::get($_config,'stmts',NULL);

//Compile the prepared statment

if(isset($_configStmts[$stmtName])){

self::compile($stmtName,$_configStmts[$stmtName],$db);

}else{

return false;

}

return DB::query(DB::SELECT,NULL,$as_object,$params,$stmtName)->execute($db);

}

}

}

php 预编译,预编译的prepare statements 管理, 实现和思路相关推荐

  1. 反编译与反汇编、C++编译过程,包括预编译--汇编--编译--链接

    参考:C/C++程序编译流程(预处理->编译->汇编->链接) - ProLyn - 博客园 反汇编和反编译的区别_代码小卒_新浪博客 反汇编与反编译: 汇编:是把汇编源程序转变为目 ...

  2. android ART编译预优化

    点击打开链接 编译预优化 DEX文件编译比较花费时间.这在OTA或者工厂首次烧入程序后非常明显. 可以在BoardConfig.mk文件中使能编译预优化,在编译时将会为APK/jar做Dex优化(de ...

  3. 了解“预编译、编译、汇编、链接”这四个过程对你有很大帮

    转自:胡薇 了解"预编译.编译.汇编.链接"这四个过程对你有很大帮助-电子发烧友网 如有侵权,告知立马删除 补充:C语言条件编译及编译预处理阶段 - Rusty's code - ...

  4. python在线编译-在线编译python

    广告关闭 2017年12月,云+社区对外发布,从最开始的技术博客到现在拥有多个社区产品.未来,我们一起乘风破浪,创造无限可能. 尝试通过源码自己编译 python,使用的系统是 ubuntu14.04 ...

  5. python编译反编译,你不知道的心机与陷阱

    谈到python的文件后缀,说眼花缭乱也不为过.来看看你遇到过哪些类型! .py 如果这个不知道,呵呵-那请出门左拐,你还是充钱那个少年,没有一丝丝改变.接着打游戏去吧- .pyc 这个后缀应该算是除 ...

  6. php windows 编译,Windows编译PHP7.2拓展

    准备工作https://github.com/Microsoft/php-sdk-binary-tools下载PHP-SDK(在右边的"clone or download"点击,选 ...

  7. python3 llvmlite源码_将Paddle-Lite在树莓派上源码编译及编译python预测库

    新手使用Paddle-Lite 第一篇博客,第一次接触树莓派,把我的经历说一说. 一.为什么选Paddle-Lite? 因为我第一次接触人工智能,PaddlePaddle官网https://www.p ...

  8. 关于安卓Apk反编译 再编译回来不能正常安装的问题

    使用apktool反编译apk之后,再编译回去,发现不能正常安装,而使用ApkToolKitV3.0反编译,再编译回去就可以正常安装. 主要原因是因为使用apktool编译回没有签名. 所以不能安装, ...

  9. c mysql 编译_MySQL编译安装之cmake

    mysql版本5.5以上编译安装时需要用到软件cmake,cmake特性是独立于源码编译,编译工作可以在另外一个目录中而非源码目录中进行, mysql版本5.5以上编译安装时需要用到软件cmake,c ...

最新文章

  1. 原生JS实现苹果菜单
  2. 让互联网助小组合作一臂之力
  3. ASP.NET页面解析(3)
  4. C# unicode 编码 和 解码
  5. 网页无障碍php,【译】开发无障碍的Web组件
  6. c语言程序设计的常用算法,《C语言程序设计的常用算法.doc
  7. 访问网站403错误解决方法(apache)
  8. unity的函数生命周期
  9. 偷窥桌面程序和IE浏览器的密码编辑框
  10. zzuli:1047对数表
  11. Principle 5.14 完美汉化版 Mac平台交互动效设计神器
  12. 最新中国上市公司市值500强(2021年)
  13. 手机图片怎么转文本?
  14. 基于JESD204B的LMK04826时钟芯片开发笔记
  15. 富文本编辑器上传图片不显示问题
  16. 配置JAVA_HOME
  17. 美团网手机客户端产品分析
  18. 大数据要掌握哪些语言?怎样才能学好大数据?
  19. 文章《Deep Image Homography Estimation》
  20. 计算方法:三次样条插值原理

热门文章

  1. 纯C++版俄罗斯方块
  2. Android Studio Logcat 截断问题(cocos2d-x 篇)
  3. nexmo - 电话报警Alert
  4. 利用Python实现scissors-rock-paper-lizard-Spock小游戏
  5. Windows命令行下对文件做MD5校验
  6. STM32存储器 — 2STM32存储器知识的相关应用(IAP、Bit Banding)
  7. PPT设置自动保存时间 mac_群晖NAS设置苹果mac时间机器Time Machine备份
  8. bootstrap中使用日历控件
  9. 工作能力强的人,都有哪些特点?
  10. autocad2007二维图画法_CAD中如何绘制二维图形