コード例 #1
0
ファイル: Forge.php プロジェクト: titounnes/CodeIgniter4
 /**
  * Process indexes
  *
  * @param    string $table
  *
  * @return    string
  */
 protected function _processIndexes($table)
 {
     $sqls = [];
     for ($i = 0, $c = count($this->keys); $i < $c; $i++) {
         if (is_array($this->keys[$i])) {
             for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++) {
                 if (!isset($this->fields[$this->keys[$i][$i2]])) {
                     unset($this->keys[$i][$i2]);
                     continue;
                 }
             }
         } elseif (!isset($this->fields[$this->keys[$i]])) {
             unset($this->keys[$i]);
             continue;
         }
         is_array($this->keys[$i]) or $this->keys[$i] = [$this->keys[$i]];
         $sqls[] = 'CREATE INDEX ' . $this->db->escapeIdentifiers($table . '_' . implode('_', $this->keys[$i])) . ' ON ' . $this->db->escapeIdentifiers($table) . ' (' . implode(', ', $this->db->escapeIdentifiers($this->keys[$i])) . ');';
     }
     return $sqls;
 }
コード例 #2
0
 /**
  * Compile ORDER BY
  *
  * Escapes identifiers in ORDER BY statements at execution time.
  *
  * Required so that aliases are tracked properly, regardless of wether
  * orderBy() is called prior to from(), join() and prefixTable is added
  * only if needed.
  *
  * @return    string    SQL statement
  */
 protected function compileOrderBy()
 {
     if (is_array($this->QBOrderBy) && count($this->QBOrderBy) > 0) {
         for ($i = 0, $c = count($this->QBOrderBy); $i < $c; $i++) {
             if ($this->QBOrderBy[$i]['escape'] !== false && !$this->isLiteral($this->QBOrderBy[$i]['field'])) {
                 $this->QBOrderBy[$i]['field'] = $this->db->protectIdentifiers($this->QBOrderBy[$i]['field']);
             }
             $this->QBOrderBy[$i] = $this->QBOrderBy[$i]['field'] . $this->QBOrderBy[$i]['direction'];
         }
         return $this->QBOrderBy = "\nORDER BY " . implode(', ', $this->QBOrderBy);
     } elseif (is_string($this->QBOrderBy)) {
         return $this->QBOrderBy;
     }
     return '';
 }
コード例 #3
0
ファイル: Model.php プロジェクト: titounnes/CodeIgniter4
 /**
  * Provides a shared instance of the Query Builder.
  *
  * @param string $table
  *
  * @return BaseBuilder|Database\QueryBuilder
  */
 protected function builder(string $table = null)
 {
     if ($this->builder instanceof BaseBuilder) {
         return $this->builder;
     }
     $table = empty($table) ? $this->table : $table;
     // Ensure we have a good db connection
     if (!$this->db instanceof BaseConnection) {
         $this->db = Database::connect($this->DBGroup);
     }
     $this->builder = $this->db->table($table);
     return $this->builder;
 }
コード例 #4
0
 /**
  * Ensures that we have created our migrations table
  * in the database.
  */
 protected function ensureTable()
 {
     if ($this->db->tableExists($this->table)) {
         return;
     }
     $forge = \Config\Database::forge();
     $forge->addField(['version' => ['type' => 'BIGINT', 'constraint' => 20, 'null' => false], 'group' => ['type' => 'varchar', 'constraint' => 255, 'null' => false], 'time' => ['type' => 'timestamp', 'null' => false]]);
     $forge->createTable($this->table, true);
 }