/** * @brief gets last value of autoincrement * @param string $table The optional table name (will replace *PREFIX*) and add sequence suffix * @return int id * * MDB2 lastInsertID() * * Call this method right after the insert command or other functions may * cause trouble! */ public static function insertid($table = null) { self::connect(); $type = OC_Config::getValue("dbtype", "sqlite"); if ($type == 'pgsql') { $query = self::prepare('SELECT lastval() AS id'); $row = $query->execute()->fetchRow(); return $row['id']; } else { if ($type === 'mssql' || $type === 'oci') { if ($table !== null) { $prefix = OC_Config::getValue("dbtableprefix", "oc_"); $table = str_replace('*PREFIX*', $prefix, $table); } return self::$connection->lastInsertId($table); } else { if ($table !== null) { $prefix = OC_Config::getValue("dbtableprefix", "oc_"); $suffix = OC_Config::getValue("dbsequencesuffix", "_id_seq"); $table = str_replace('*PREFIX*', $prefix, $table) . $suffix; } return self::$connection->lastInsertId($table); } } }
/** * @brief gets last value of autoincrement * @param string $table The optional table name (will replace *PREFIX*) and add sequence suffix * @return int id * * MDB2 lastInsertID() * * Call this method right after the insert command or other functions may * cause trouble! */ public static function insertid($table = null) { self::connect(); if ($table !== null) { $prefix = OC_Config::getValue("dbtableprefix", "oc_"); $suffix = OC_Config::getValue("dbsequencesuffix", "_id_seq"); $table = str_replace('*PREFIX*', $prefix, $table) . $suffix; } return self::$connection->lastInsertId($table); }