<commit_before><?php
/*{{{LICENSE
+-----------------------------------------------------------------------+
| SlightPHP Framework                                                   |
+-----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify  |
| it under the terms of the GNU General Public License as published by  |
| the Free Software Foundation. You should have received a copy of the  |
| GNU General Public License along with this program.  If not, see      |
| http://www.gnu.org/licenses/.                                         |
| Copyright (C) 2008-2009. All Rights Reserved.                         |
+-----------------------------------------------------------------------+
| Supports: http://www.slightphp.com                                    |
+-----------------------------------------------------------------------+
}}}*/
require_once(dirname(__FILE__)."/db/DbData.php");
require_once(dirname(__FILE__)."/db/DbObject.php");
require_once(dirname(__FILE__)."/db/Db.php");
/**
 * @package SlightPHP
 */
class SDb extends Db{

		static $_DbConfigFile;
		static $_DbdefaultZone="default";
		static $_DbConfigCache;
		/**
		 * @deprecated
		 * @return class Db
		 */
		static function getDbEngine($engine){
				$engine = strtolower($engine);
				if(!in_array($engine,array("mysql","pdo_mysql"))){
						return false;
				}
				if($engine=="mysql" && extension_loaded("mysql")){
						require_once(dirname(__FILE__).DIRECTORY_SEPARATOR."db/Db_Mysql.php");
						return new Db_Mysql;
				}elseif($engine=="pdo_mysql"){
						require_once(dirname(__FILE__).DIRECTORY_SEPARATOR."db/Db_PDO.php");
						return new Db_PDO("mysql");
				}
		}
		static function setConfigFile($file){
				SDb::$_DbConfigFile = $file;
		}
		static function getConfigFile(){
				return SDb::$_DbConfigFile;
		}
		/**
		 * @param string $zone
		 * @param string $type	main|query
		 * @return array
		 */
		static function getConfig($zone,$type="main"){
				if(!SDb::$_DbConfigFile){return array();}


				$cache = &SDb::$_DbConfigCache;
				if(isset($cache[$zone]) && isset($cache[$zone][$type])){
						$i =  array_rand($cache[$zone][$type]);
						return $cache[$zone][$type][$i];
				}

				$file_data = parse_ini_file(realpath(SDb::$_DbConfigFile),true);
				if(isset($file_data[$zone])){
						$db = $file_data[$zone];
				}elseif(isset($file_data[SDb::$_DbdefaultZone])){
						$db = $file_data[SDb::$_DbdefaultZone];
				}else{
						return array();
				}
				//no query to direct to main
				$query_flag = false;
				foreach($db as $key =>$row){
						if(strpos($key,"main")!==false){
								$index = "main";
						}elseif(strpos($key,"query")!==false){
								$index = "query";
						}else{
								continue;
						}
						$row = str_replace(":","=",$row);
						$row = str_replace(",","&",$row);
						parse_str($row,$out);
						if(!empty($out)){
								if(strpos($key,"query")!==false)$query_flag = true;
								$cache[$zone][$index][]=$out;
						}

				}
				if(!$query_flag){
						$type = "main";
				}
				$i =  array_rand($cache[$zone][$type]);
				return $cache[$zone][$type][$i];
		}
		/**
		 * 切换数据库配置文件
		 * $param string $zone
		 * $param string $type="main"
		 */
		function useConfig($zone,$type="main"){
			$this->init(SDb::getConfig($zone,$type));
		}




		private $foreign_keys =array();
		private $table_name=""; //表名，默认和 类名 user 一样


		/**
		 * 字段属性结构
		 * $user->id=1;
		 * $user->name="XX";
		 * $user->nickname="nickname";
		 * $user->profile->address="my address";
		 * $user->profile->comment="comment";
		 */
		private $_fields;
		public function __get($k){
				if(isset($this->_fields->$k)){
						return $this->_fields->$k;
				}else{
						//判断是不是属于外键
						foreach($this->foreign_keys as $k2=>$v2){
								$tmp = explode(".",$v2);
								if(!empty($tmp[0]) && !empty($tmp[1])){
										$tbl_name = trim($tmp[0]);
										if($k==$tbl_name)<commit_msg>SDb 命令方法调整<commit_after><?php
/*{{{LICENSE
+-----------------------------------------------------------------------+
| SlightPHP Framework                                                   |
+-----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify  |
| it under the terms of the GNU General Public License as published by  |
| the Free Software Foundation. You should have received a copy of the  |
| GNU General Public License along with this program.  If not, see      |
| http://www.gnu.org/licenses/.                                         |
| Copyright (C) 2008-2009. All Rights Reserved.                         |
+-----------------------------------------------------------------------+
| Supports: http://www.slightphp.com                                    |
+-----------------------------------------------------------------------+
}}}*/
require_once(dirname(__FILE__)."/db/DbData.php");
require_once(dirname(__FILE__)."/db/DbObject.php");
require_once(dirname(__FILE__)."/db/Db.php");
/**
 * @package SlightPHP
 */
class SDb extends Db{

		private static $_DbConfigFile;
		private static $_DbdefaultZone="default";
		private static $_DbConfigCache;
		/**
		 * @deprecated
		 * @return class Db
		 */
		static function getDbEngine($engine){
				$engine = strtolower($engine);
				if(!in_array($engine,array("mysql","pdo_mysql"))){
						return false;
				}
				if($engine=="mysql" && extension_loaded("mysql")){
						require_once(dirname(__FILE__).DIRECTORY_SEPARATOR."db/Db_Mysql.php");
						return new Db_Mysql;
				}elseif($engine=="pdo_mysql"){
						require_once(dirname(__FILE__).DIRECTORY_SEPARATOR."db/Db_PDO.php");
						return new Db_PDO("mysql");
				}
		}
		static function setConfigFile($file){
				self::$_DbConfigFile = $file;
		}
		static function getConfigFile(){
				return self::$_DbConfigFile;
		}
		/**
		 * @param string $zone
		 * @param string $type	main|query
		 * @return array
		 */
		static function getConfig($zone,$type="main"){
				if(!self::$_DbConfigFile){return array();}


				$cache = &self::$_DbConfigCache;
				if(isset($cache[$zone]) && isset($cache[$zone][$type])){
						$i =  array_rand($cache[$zone][$type]);
						return $cache[$zone][$type][$i];
				}

				$file_data = parse_ini_file(realpath(self::$_DbConfigFile),true);
				if(isset($file_data[$zone])){
						$db = $file_data[$zone];
				}elseif(isset($file_data[self::$_DbdefaultZone])){
						$db = $file_data[self::$_DbdefaultZone];
				}else{
						return array();
				}
				//no query to direct to main
				$query_flag = false;
				foreach($db as $key =>$row){
						if(strpos($key,"main")!==false){
								$index = "main";
						}elseif(strpos($key,"query")!==false){
								$index = "query";
						}else{
								continue;
						}
						$row = str_replace(":","=",$row);
						$row = str_replace(",","&",$row);
						parse_str($row,$out);
						if(!empty($out)){
								if(strpos($key,"query")!==false)$query_flag = true;
								$cache[$zone][$index][]=$out;
						}

				}
				if(!$query_flag){
						$type = "main";
				}
				$i =  array_rand($cache[$zone][$type]);
				return $cache[$zone][$type][$i];
		}
		/**
		 * 切换数据库配置文件
		 * $param string $zone
		 * $param string $type="main"
		 */
		function useConfig($zone,$type="main"){
			$this->init(self::getConfig($zone,$type));
		}




		private $foreign_keys =array();
		private $table_name=""; //表名，默认和 类名 user 一样


		/**
		 * 字段属性结构
		 * $user->id=1;
		 * $user->name="XX";
		 * $user->nickname="nickname";
		 * $user->profile->address="my address";
		 * $user->profile->comment="comment";
		 */
		private $_fields;
		public function __get($k){
				if(isset($this->_fields->$k)){
						return $this->_fields->$k;
				}else{
						//判断是不是属于外键
						foreach($this->foreign_keys as $k2=>$v2){
								$tmp = explode(".",$v2);
								if(!empty($tmp[0]) && !empty($tmp[1])){
										$tbl_name = trim($tmp[0]);
										if($k==$tbl_name)
{'fraction_non_alphanumeric': 0.2452664576802508, 'fraction_numerical': 0.003761755485893417, 'mean_word_length': 2.189124350259896, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5134674', 'n_tokens_mistral': 3168, 'n_tokens_neox': 2499, 'n_words': 449}