function _insertid() { return fbsql_insert_id($this->_connectionID); }
/** * get last insert ID * * @return mixed MDB2 Error Object or id * @access public */ function getInsertID() { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; return fbsql_insert_id($db->connection); }
/** * Returns the next free id in a sequence * * @param string $seq_name name of the sequence * @param boolean $ondemand when true, the seqence is automatically * created if it does not exist * * @return int the next id number in the sequence. DB_Error if problem. * * @internal * @see DB_common::nextID() * @access public */ function nextId($seq_name, $ondemand = true) { $seqname = $this->getSequenceName($seq_name); $repeat = 0; do { $result = $this->query("INSERT INTO {$seqname} VALUES(NULL)"); if ($ondemand && DB::isError($result) && $result->getCode() == DB_ERROR_NOSUCHTABLE) { $repeat = 1; $result = $this->createSequence($seq_name); if (DB::isError($result)) { return $result; } } else { $repeat = 0; } } while ($repeat); if (DB::isError($result)) { return $result; } return @fbsql_insert_id($this->connection); }
/** * Get the next value in a sequence. We emulate sequences * for fbsql. Will create the sequence if it does not exist. * * @access public * * @param $seq_name the name of the sequence * * @param $ondemand whether to create the sequence table on demand * (default is true) * * @return a sequence integer, or a DB error */ function nextId($seq_name, $ondemand = true) { $sqn = preg_replace('/[^a-z0-9_]/i', '_', $seq_name); $repeat = 0; do { $seqname = sprintf($this->getOption("seqname_format"), $sqn); $result = $this->query("INSERT INTO {$seqname} VALUES(NULL)"); if ($ondemand && DB::isError($result) && $result->getCode() == DB_ERROR_NOSUCHTABLE) { $repeat = 1; $result = $this->createSequence($seq_name); if (DB::isError($result)) { return $result; } } else { $repeat = 0; } } while ($repeat); if (DB::isError($result)) { return $result; } return fbsql_insert_id($this->connection); }
/** * returns the next free id of a sequence * * @param string $seq_name name of the sequence * @param boolean $ondemand when true the seqence is * automatic created, if it * not exists * * @return mixed MDB_Error or id * @access public */ function nextId($seq_name, $ondemand = TRUE) { $sequence_name = $this->getSequenceName($seq_name); $this->expectError(MDB_ERROR_NOSUCHTABLE); $result = $this->query("INSERT INTO {$sequence_name} VALUES (NULL)"); $this->popExpect(); if ($ondemand && MDB::isError($result) && $result->getCode() == MDB_ERROR_NOSUCHTABLE) { // Since we are create the sequence on demand // we know the first id = 1 so initialize the // sequence at 2 $result = $this->createSequence($seq_name, 2); if (MDB::isError($result)) { return $this->raiseError(MDB_ERROR, NULL, NULL, 'Next ID: on demand sequence could not be created'); } else { // First ID of a newly created sequence is 1 return 1; } } $value = intval(@fbsql_insert_id()); $res = $this->query("DELETE FROM {$sequence_name} WHERE " . $this->options['sequence_col_name'] . " < {$value}"); if (MDB::isError($res)) { $this->warnings[] = 'Next ID: could not delete previous sequence table values'; } return $value; }
public function insertId() { if (!empty($this->connect)) { return fbsql_insert_id($this->connect); } else { return false; } }
/** * Returns the autoincrement ID if supported or $id or fetches the current * ID in a sequence called: $table.(empty($field) ? '' : '_'.$field) * * @param string $table name of the table into which a new row was inserted * @param string $field name of the field into which a new row was inserted * @return mixed MDB2 Error Object or id * @access public */ function lastInsertID($table = null, $field = null) { $connection = $this->getConnection(); if (MDB2::isError($connection)) { return $connection; } $value = @fbsql_insert_id($connection); if (!$value) { return $this->raiseError(null, null, null, 'Could not get last insert ID', __FUNCTION__); } return $value; }
/** * returns the autoincrement ID if supported or $id * * @param mixed $id value as returned by getBeforeId() * @param string $table name of the table into which a new row was inserted * @return mixed MDB2 Error Object or id * @access public */ function lastInsertID($table = null, $field = null) { $connection = $this->getConnection(); if (PEAR::isError($connection)) { return $connection; } $value = @fbsql_insert_id($connection); if (!$value) { return $this->raiseError(); } return $value; }