View | Details | Raw Unified | Return to bug 8252 | Differences between
and this patch

Collapse All | Expand All

(-)a/lib/adodb/drivers/adodb-postgres64.inc.php (-9 / +20 lines)
 Lines 162-178   a different OID if a database must be reloaded. */ Link Here 
162
162
163
	// Added 2004-06-27 by Kevin Jamieson (http://pkp.sfu.ca/)
163
	// Added 2004-06-27 by Kevin Jamieson (http://pkp.sfu.ca/)
164
	// Insert_ID function that returns the actual field value instead of the OID
164
	// Insert_ID function that returns the actual field value instead of the OID
165
	function PO_Insert_ID($table="", $id="") {
165
	function PO_Insert_ID($table='', $id='') {
166
		if (!empty($table) && !empty($id)) {
166
		// If no table is specified, we can use LASTVAL()
167
			$result = @pg_exec("SELECT CURRVAL('{$table}_{$id}_seq')");
167
		if ($table === '') {
168
			if ($result) {
168
			$result = pg_exec("SELECT LASTVAL()");
169
				$row = @pg_fetch_row($result, 0);
169
			$row = pg_fetch_row($result, 0);
170
				if (isset($row[0])) {
170
			return $row[0];
171
					return $row[0];
171
		}
172
				}
172
173
		// If a table is specified, try to get the sequence name
174
		foreach($this->MetaColumns($table) as $fld) {
175
			if (
176
				isset($fld->primary_key) && $fld->primary_key && $fld->has_default &&
177
				preg_match("/nextval\('(?:[^']+\.)*([^']+)'::(text|regclass)\)/",$fld->default_value,$matches) &&
178
				($fld->name == $id || $id == '') // Field matches supplied var or none supplied
179
			) {
180
				$result = pg_exec('SELECT CURRVAL(\'' . $matches[1] . '\')');
181
				$row = pg_fetch_row($result, 0);
182
				return $row[0];
173
			}
183
			}
174
		}
184
		}
175
		
185
186
		// Fall back on the OID
176
		return $this->_insertid($table, $id);
187
		return $this->_insertid($table, $id);
177
	}
188
	}
178
189

Return to bug 8252