// Extras - We dont want to affect $this
+ // Type
+ if (isset($opt['sql'])) {
+ unset($opt['type']);
+ $this->type = 'sql';
+ }
+
// Extras
if (isset($opt['extras'])) {
$this->add_extras($opt['extras']);
*/
public function indexes() {
if (!isset($this->indexes)) {
- $sql = str_replace('<NAME>',$this->name,$this->db()->type('table.sql.index'));
- if (is_array($sql)) list($sql,$fct) = count($sql)==1 ? [$sql[0],null] : $sql;
+ $sql = $this->db()->type('table.sql.index');
+ $fct = '';
+
+ if (is_array($sql)) list($sql,$fct) = (count($sql)==1 ? [$sql[0],null] : $sql);
if (!$sql) return [];
+ $sql = str_replace('<NAME>',$this->name,$sql);
+ $sql = str_replace('<DB>',$this->db()->name,$sql);
$st = $this->db()->conn->prepare($sql);
$st->execute();
$this->indexes = [];
*/
public function fields($name=null) {
- if (!empty($this->sql)) return []; # Virtual - NB 04.07.16
+ #if (!empty($this->sql)) return []; # Virtual - NB 04.07.16
+ if ($this->type == 'sql') return []; # Virtual - NB 04.07.16
if (!isset($this->fields)) {
$this->fields = array();
'localFile' => array (getenv('HOME').'/.my.cnf','^(?:user(?:name)?=(?P<user>\\S+)|password=(?P<password>\\S+))'),
'table.sql' => 'SHOW CREATE TABLE `<NAME>`',
-'table.sql.index' => [
- 'SHOW INDEX FROM `<NAME>`', function(&$r) {
- if ($r['Key_name'] != 'PRIMARY') return [
- 'id' => $r['Key_name'],
- 'field' => $r['Column_name'],
- 'uniq' => ($r['Non_unique'] ? 0 : 1),
- 'type' => $r['Index_type']
- ];
- },
-],
+'table.sql.index' => "SELECT ".(Db::p('db.type') ? "CONCAT(s.TABLE_NAME,'_',s.INDEX_NAME,'_idx')" : 's.INDEX_NAME')." as name,(CASE NON_UNIQUE WHEN 1 THEN 0 ELSE 1 END) as uniqe,GROUP_CONCAT(COLUMN_NAME) as field FROM INFORMATION_SCHEMA.STATISTICS s LEFT OUTER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS t ON t.TABLE_SCHEMA=s.TABLE_SCHEMA AND t.TABLE_NAME=s.TABLE_NAME AND s.INDEX_NAME=t.CONSTRAINT_NAME WHERE 0=0 AND t.CONSTRAINT_NAME IS NULL AND s.TABLE_SCHEMA = '<DB>' AND s.TABLE_NAME='<NAME>' GROUP BY name ORDER BY SEQ_IN_INDEX",
+# NB 04.07.16 '_table.sql.index' => [
+# NB 04.07.16 'SHOW INDEX FROM `<NAME>`', function(&$r) {
+# NB 04.07.16 if ($r['Key_name'] != 'PRIMARY') return [
+# NB 04.07.16 'name' => $r['Key_name'],
+# NB 04.07.16 'field' => $r['Column_name'],
+# NB 04.07.16 'uniq' => ($r['Non_unique'] ? 0 : 1),
+# NB 04.07.16 'type' => $r['Index_type']
+# NB 04.07.16 ];
+# NB 04.07.16 },
+# NB 04.07.16 ],
'tables' => 'SELECT TABLE_NAME as name,LOWER(IF(TABLE_TYPE=\'BASE TABLE\',\'TABLE\',TABLE_TYPE)) as type,ENGINE as engine,CREATE_TIME as created FROM information_schema.tables WHERE TABLE_SCHEMA=DATABASE()',
'sql.replace' => function($sql) {
$sql = preg_replace('/ESCAPE \'.*?\'/','',$sql);
- $sql = preg_replace('/CHARSET=latin1\s*$/','CHARSET='.str_replace('-','',Db::$encoding),$sql);
+ $sql = preg_replace('/CHARSET=\S+\s*$/','CHARSET='.str_replace('-','',Db::$encoding),$sql);
return $sql;
},