/** * Calls the underlying database to quote value * @param string $v * @param epFieldMap $fm * @return string */ public function quote($v, $fm = false) { return self::$db->quote($v, $fm); }
/** * Make a SQL insert statement from object variables * @param epDbObject $db the db connection * @param epObject the object for query * @param epClassMap the class map for the object * @return false|string */ public static function sqlInsert($db, $cm, $o) { // get all vars if (!($vars = $o->epGetVars())) { return false; } // make select statement $sql = 'INSERT INTO ' . $db->quoteId($cm->getTable()) . ' ('; // get column names $i = 0; while (list($var, $val) = each($vars)) { // exclude 'oid' if ($var == 'oid') { continue; } // shouldn't happen if (!($fm = $cm->getField($var))) { continue; } // exclude non-primitive fields if (!$fm->isPrimitive()) { continue; } $sql .= $db->quoteId($fm->getColumnName()) . ', '; $i++; } // no need to insert if we don't have any var to insert if ($i == 0) { $sql .= $db->quoteId($cm->getOidColumn()) . ') VALUES (' . $db->quote('', $fm) . ');'; return $sql; } // remove the last ', ' if ($i > 0) { $sql = substr($sql, 0, strlen($sql) - 2); } $sql .= ') VALUES ('; // get values $i = 0; reset($vars); while (list($var, $val) = each($vars)) { // exclude 'oid' if ($var == 'oid') { continue; } if (!($fm =& $cm->getField($var))) { continue; } // exclude non-primitive fields if (!$fm->isPrimitive()) { continue; } // get quoted field value $sql .= $db->quote($val, $fm) . ', '; ++$i; } // remove the last ', ' if ($i > 0) { $sql = substr($sql, 0, strlen($sql) - 2); } // end of statement $sql .= ');'; return $sql; }