Exemplo n.º 1
0
 /**
  * Overrides {@link epDbPort::insertValues()}
  * Returns the insert SQL statement
  * 
  * Pgsql does not allow to insert multiple rows in one INSERT
  * statement. So we need to create multiple INSERT statements.
  * 
  * @param string $table
  * @param epDb $db
  * @param array $cols The names of the columns to be inserted 
  * @param array $rows The rows of values to be inserted
  * @return string|array
  */
 public function insertValues($table, $db, $cols, $rows)
 {
     // make insert sql stmt
     $sql_header = 'INSERT INTO ' . $db->quoteId($table) . ' (';
     // get all column names
     $cols_q = array();
     foreach ($cols as $col) {
         $cols_q[] = $db->quoteId($col);
     }
     $sql_header .= implode(',', $cols_q) . ') VALUES ';
     // array to hold sql statements
     $sqls = array();
     // collect all sql statements
     foreach ($rows as $row) {
         // collect all values
         $row_q = array();
         foreach ($row as $col_value) {
             $row_q[] = $db->quote($col_value);
         }
         // make one sql statement
         $sqls[] = $sql_header . '(' . implode(',', $row_q) . ')';
     }
     return $sqls;
 }
Exemplo n.º 2
0
 /**
  * SQL to create unique keys
  * @param epClassMap $cm
  * @param epDb $db
  * @param string $indent
  * @return string
  */
 protected function _uniqueKeys($cm, $db, $indent = '  ')
 {
     $sql = '';
     foreach ($cm->getUniqueKeys() as $name => $key) {
         // quote keys
         foreach ($key as $k => $v) {
             $key[$k] = $db->quoteId($v);
         }
         // get stmt for this key
         $sql .= $indent . $this->_uniqueKey($db->quoteId($name), $key) . ",\n";
     }
     return $sql;
 }
Exemplo n.º 3
0
 /**
  * Wraps around {@link epDb::quoteId()}
  * Formats a string so it can be safely used as an identifier (e.g. table, column names)
  * @param string $id
  * @return mixed
  */
 public function quoteId($id)
 {
     return $this->db->quoteId($id);
 }
Exemplo n.º 4
0
 /**
  * SQL to truncate (empty) table 
  * @param string $table
  * @param epDb $db
  * @return string
  */
 public function truncateTable($table, $db)
 {
     return 'TRUNCATE TABLE  ' . $db->quoteId($table) . ";\n";
 }
 /**
  * SQL to truncate (empty) table 
  * @param string $table
  * @param epDb $db
  * @return string
  */
 public function truncateTable($table, $db)
 {
     return 'DELETE FROM  ' . $db->quoteId($table) . " WHERE 1;\n";
 }
 /**
  * SQL to truncate (empty) table
  * @param string $table
  * @param epDb $db
  * @return string
  */
 public function truncateTable($table, $db)
 {
     //return 'DELETE FROM ' . $table . " WHERE 1=1;\n";
     return 'TRUNCATE TABLE  ' . $db->quoteId($table) . ";\n";
 }