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

Collapse All | Expand All

(-)a/dbscripts/xml/upgrade/2.2.0_update.xml (-33 / +33 lines)
 Lines 14-52    Link Here 
14
<data>
14
<data>
15
	<!-- Make sure PostgreSQL sequences are starting from the right values -->
15
	<!-- Make sure PostgreSQL sequences are starting from the right values -->
16
	<sql>
16
	<sql>
17
		<query driver="postgres7">SELECT SETVAL('users_user_id_seq', (SELECT MAX(user_id) FROM users)+1)</query>
17
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('users', 'user_id'), (SELECT MAX(user_id) FROM users)+1)</query>
18
		<query driver="postgres7">SELECT SETVAL('auth_sources_auth_id_seq', (SELECT MAX(auth_id) FROM auth_sources)+1)</query>
18
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('auth_sources', 'auth_id'), (SELECT MAX(auth_id) FROM auth_sources)+1)</query>
19
		<query driver="postgres7">SELECT SETVAL('journals_journal_id_seq', (SELECT MAX(journal_id) FROM journals)+1)</query>
19
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('journals', 'journal_id'), (SELECT MAX(journal_id) FROM journals)+1)</query>
20
		<query driver="postgres7">SELECT SETVAL('sections_section_id_seq', (SELECT MAX(section_id) FROM sections)+1)</query>
20
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('sections', 'section_id'), (SELECT MAX(section_id) FROM sections)+1)</query>
21
		<query driver="postgres7">SELECT SETVAL('issues_issue_id_seq', (SELECT MAX(issue_id) FROM issues)+1)</query>
21
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('issues', 'issue_id'), (SELECT MAX(issue_id) FROM issues)+1)</query>
22
		<query driver="postgres7">SELECT SETVAL('articles_article_id_seq', (SELECT MAX(article_id) FROM articles)+1)</query>
22
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('articles', 'article_id'), (SELECT MAX(article_id) FROM articles)+1)</query>
23
		<query driver="postgres7">SELECT SETVAL('published_articles_pub_id_seq', (SELECT MAX(pub_id) FROM published_articles)+1)</query>
23
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('published_articles', 'pub_id'), (SELECT MAX(pub_id) FROM published_articles)+1)</query>
24
		<query driver="postgres7">SELECT SETVAL('comments_comment_id_seq', (SELECT MAX(comment_id) FROM comments)+1)</query>
24
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('comments', 'comment_id'), (SELECT MAX(comment_id) FROM comments)+1)</query>
25
		<query driver="postgres7">SELECT SETVAL('authors_author_id_seq', (SELECT MAX(author_id) FROM authors)+1)</query>
25
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('authors', 'author_id'), (SELECT MAX(author_id) FROM authors)+1)</query>
26
		<query driver="postgres7">SELECT SETVAL('article_files_file_id_seq', (SELECT MAX(file_id) FROM article_files)+1)</query>
26
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('article_files', 'file_id'), (SELECT MAX(file_id) FROM article_files)+1)</query>
27
		<query driver="postgres7">SELECT SETVAL('article_supplementary_files_supp_id_seq', (SELECT MAX(supp_id) FROM article_supplementary_files)+1)</query>
27
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('article_supplementary_files', 'supp_id'), (SELECT MAX(supp_id) FROM article_supplementary_files)+1)</query>
28
		<query driver="postgres7">SELECT SETVAL('article_notes_note_id_seq', (SELECT MAX(note_id) FROM article_notes)+1)</query>
28
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('article_notes', 'note_id'), (SELECT MAX(note_id) FROM article_notes)+1)</query>
29
		<query driver="postgres7">SELECT SETVAL('edit_assignments_edit_id_seq', (SELECT MAX(edit_id) FROM edit_assignments)+1)</query>
29
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('edit_assignments', 'edit_id'), (SELECT MAX(edit_id) FROM edit_assignments)+1)</query>
30
		<query driver="postgres7">SELECT SETVAL('edit_decisions_edit_decision_id_seq', (SELECT MAX(edit_decision_id) FROM edit_decisions)+1)</query>
30
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('edit_decisions', 'edit_decision_id'), (SELECT MAX(edit_decision_id) FROM edit_decisions)+1)</query>
31
		<query driver="postgres7">SELECT SETVAL('review_assignments_review_id_seq', (SELECT MAX(review_id) FROM review_assignments)+1)</query>
31
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('review_assignments', 'review_id'), (SELECT MAX(review_id) FROM review_assignments)+1)</query>
32
		<query driver="postgres7">SELECT SETVAL('article_galleys_galley_id_seq', (SELECT MAX(galley_id) FROM article_galleys)+1)</query>
32
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('article_galleys', 'galley_id'), (SELECT MAX(galley_id) FROM article_galleys)+1)</query>
33
		<query driver="postgres7">SELECT SETVAL('article_event_log_log_id_seq', (SELECT MAX(log_id) FROM article_event_log)+1)</query>
33
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('article_event_log', 'log_id'), (SELECT MAX(log_id) FROM article_event_log)+1)</query>
34
		<query driver="postgres7">SELECT SETVAL('article_email_log_log_id_seq', (SELECT MAX(log_id) FROM article_email_log)+1)</query>
34
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('article_email_log', 'log_id'), (SELECT MAX(log_id) FROM article_email_log)+1)</query>
35
		<query driver="postgres7">SELECT SETVAL('article_comments_comment_id_seq', (SELECT MAX(comment_id) FROM article_comments)+1)</query>
35
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('article_comments', 'comment_id'), (SELECT MAX(comment_id) FROM article_comments)+1)</query>
36
		<query driver="postgres7">SELECT SETVAL('email_templates_default_email_id_seq', (SELECT MAX(email_id) FROM email_templates_default)+1)</query>
36
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('article_email_templates', 'email_id'), (SELECT MAX(email_id) FROM email_templates_default)+1)</query>
37
		<query driver="postgres7">SELECT SETVAL('email_templates_email_id_seq', (SELECT MAX(email_id) FROM email_templates)+1)</query>
37
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('email_templates', 'email_id'), (SELECT MAX(email_id) FROM email_templates)+1)</query>
38
		<query driver="postgres7">SELECT SETVAL('article_search_keyword_list_keyword_id_seq', (SELECT MAX(keyword_id) FROM article_search_keyword_list)+1)</query>
38
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('article_search_keyword_list', 'keyword_id'), (SELECT MAX(keyword_id) FROM article_search_keyword_list)+1)</query>
39
		<query driver="postgres7">SELECT SETVAL('article_search_objects_object_id_seq', (SELECT MAX(object_id) FROM article_search_objects)+1)</query>
39
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('article_search_objects', 'object_id'), (SELECT MAX(object_id) FROM article_search_objects)+1)</query>
40
		<query driver="postgres7">SELECT SETVAL('rt_versions_version_id_seq', (SELECT MAX(version_id) FROM rt_versions)+1)</query>
40
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('rt_versions', 'version_id'), (SELECT MAX(version_id) FROM rt_versions)+1)</query>
41
		<query driver="postgres7">SELECT SETVAL('rt_contexts_context_id_seq', (SELECT MAX(context_id) FROM rt_contexts)+1)</query>
41
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('rt_contexts', 'context_id'), (SELECT MAX(context_id) FROM rt_contexts)+1)</query>
42
		<query driver="postgres7">SELECT SETVAL('rt_searches_search_id_seq', (SELECT MAX(search_id) FROM rt_searches)+1)</query>
42
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('rt_searches', 'search_id'), (SELECT MAX(search_id) FROM rt_searches)+1)</query>
43
		<query driver="postgres7">SELECT SETVAL('subscription_types_type_id_seq', (SELECT MAX(type_id) FROM subscription_types)+1)</query>
43
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('subscription_types', 'type_id'), (SELECT MAX(type_id) FROM subscription_types)+1)</query>
44
		<query driver="postgres7">SELECT SETVAL('subscriptions_subscription_id_seq', (SELECT MAX(subscription_id) FROM subscriptions)+1)</query>
44
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('subscriptions', 'subscription_id'), (SELECT MAX(subscription_id) FROM subscriptions)+1)</query>
45
		<query driver="postgres7">SELECT SETVAL('announcement_types_type_id_seq', (SELECT MAX(type_id) FROM announcement_types)+1)</query>
45
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('announcement_types', 'type_id'), (SELECT MAX(type_id) FROM announcement_types)+1)</query>
46
		<query driver="postgres7">SELECT SETVAL('announcements_announcement_id_seq', (SELECT MAX(announcement_id) FROM announcements)+1)</query>
46
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('announcements', 'announcement_id'), (SELECT MAX(announcement_id) FROM announcements)+1)</query>
47
		<query driver="postgres7">SELECT SETVAL('temporary_files_file_id_seq', (SELECT MAX(file_id) FROM temporary_files)+1)</query>
47
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('temporary_files', 'file_id'), (SELECT MAX(file_id) FROM temporary_files)+1)</query>
48
		<query driver="postgres7">SELECT SETVAL('access_keys_access_key_id_seq', (SELECT MAX(access_key_id) FROM access_keys)+1)</query>
48
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('access_keys', 'access_key_id'), (SELECT MAX(access_key_id) FROM access_keys)+1)</query>
49
		<query driver="postgres7">SELECT SETVAL('groups_group_id_seq', (SELECT MAX(group_id) FROM groups)+1)</query>
49
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('groups', 'group_id'), (SELECT MAX(group_id) FROM groups)+1)</query>
50
	</sql>
50
	</sql>
51
51
52
	<!-- #2424# Drop the currencies table after the FKs have been kept. -->
52
	<!-- #2424# Drop the currencies table after the FKs have been kept. -->
(-)a/dbscripts/xml/upgrade/2.4.0_idupgrade_article_galleys2.xml (-1 / +1 lines)
 Lines 17-23    Link Here 
17
		  - Migrate public IDs to settings tables.
17
		  - Migrate public IDs to settings tables.
18
		  -->
18
		  -->
19
		<query>INSERT INTO article_galleys (galley_id, locale, article_id, file_id, label, html_galley, style_file_id, seq, views) SELECT galley_id, locale, article_id, file_id, label, html_galley, style_file_id, seq, views FROM article_galleys_old</query>
19
		<query>INSERT INTO article_galleys (galley_id, locale, article_id, file_id, label, html_galley, style_file_id, seq, views) SELECT galley_id, locale, article_id, file_id, label, html_galley, style_file_id, seq, views FROM article_galleys_old</query>
20
		<query driver="postgres7">SELECT SETVAL('article_galleys_galley_id_seq', (SELECT MAX(galley_id) FROM article_galleys)+1)</query>
20
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('article_galleys', 'galley_id'), (SELECT MAX(galley_id) FROM article_galleys)+1)</query>
21
 		<query>INSERT INTO article_galley_settings (galley_id, setting_name, setting_value, setting_type, locale) SELECT galley_id, 'pub-id::publisher-id', public_galley_id, 'string', '' FROM article_galleys_old</query>
21
 		<query>INSERT INTO article_galley_settings (galley_id, setting_name, setting_value, setting_type, locale) SELECT galley_id, 'pub-id::publisher-id', public_galley_id, 'string', '' FROM article_galleys_old</query>
22
		<query>DROP TABLE article_galleys_old</query>
22
		<query>DROP TABLE article_galleys_old</query>
23
	</sql>
23
	</sql>
(-)a/dbscripts/xml/upgrade/2.4.0_idupgrade_articles2.xml (-1 / +1 lines)
 Lines 17-23    Link Here 
17
		  - Migrate public IDs to settings tables.
17
		  - Migrate public IDs to settings tables.
18
		  -->
18
		  -->
19
		<query>INSERT INTO articles (article_id, locale, user_id, journal_id, section_id, language, comments_to_ed, citations, date_submitted, last_modified, date_status_modified, status, submission_progress, current_round, submission_file_id, revised_file_id, review_file_id, editor_file_id, pages, fast_tracked, hide_author, comments_status) SELECT article_id, locale, user_id, journal_id, section_id, language, comments_to_ed, citations, date_submitted, last_modified, date_status_modified, status, submission_progress, current_round, submission_file_id, revised_file_id, review_file_id, editor_file_id, pages, fast_tracked, hide_author, comments_status FROM articles_old</query>
19
		<query>INSERT INTO articles (article_id, locale, user_id, journal_id, section_id, language, comments_to_ed, citations, date_submitted, last_modified, date_status_modified, status, submission_progress, current_round, submission_file_id, revised_file_id, review_file_id, editor_file_id, pages, fast_tracked, hide_author, comments_status) SELECT article_id, locale, user_id, journal_id, section_id, language, comments_to_ed, citations, date_submitted, last_modified, date_status_modified, status, submission_progress, current_round, submission_file_id, revised_file_id, review_file_id, editor_file_id, pages, fast_tracked, hide_author, comments_status FROM articles_old</query>
20
		<query driver="postgres7">SELECT SETVAL('articles_article_id_seq', (SELECT MAX(article_id) FROM articles)+1)</query>
20
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('articles', 'article_id'), (SELECT MAX(article_id) FROM articles)+1)</query>
21
		<query>INSERT INTO article_settings (article_id, setting_name, setting_value, setting_type, locale) SELECT article_id, 'pub-id::doi', doi, 'string', '' FROM articles_old WHERE doi IS NOT NULL AND doi != ''</query>
21
		<query>INSERT INTO article_settings (article_id, setting_name, setting_value, setting_type, locale) SELECT article_id, 'pub-id::doi', doi, 'string', '' FROM articles_old WHERE doi IS NOT NULL AND doi != ''</query>
22
		<query>DROP TABLE articles_old</query>
22
		<query>DROP TABLE articles_old</query>
23
	</sql>
23
	</sql>
(-)a/dbscripts/xml/upgrade/2.4.0_idupgrade_issues2.xml (-1 / +1 lines)
 Lines 17-23    Link Here 
17
		  - Migrate public IDs to settings tables.
17
		  - Migrate public IDs to settings tables.
18
		  -->
18
		  -->
19
		<query>INSERT INTO issues (issue_id, journal_id, volume, number, year, published, current, date_published, date_notified, access_status, open_access_date, show_volume, show_number, show_year, show_title, style_file_name, original_style_file_name) SELECT issue_id, journal_id, volume, number, year, published, current, date_published, date_notified, access_status, open_access_date, show_volume, show_number, show_year, show_title, style_file_name, original_style_file_name FROM issues_old</query>
19
		<query>INSERT INTO issues (issue_id, journal_id, volume, number, year, published, current, date_published, date_notified, access_status, open_access_date, show_volume, show_number, show_year, show_title, style_file_name, original_style_file_name) SELECT issue_id, journal_id, volume, number, year, published, current, date_published, date_notified, access_status, open_access_date, show_volume, show_number, show_year, show_title, style_file_name, original_style_file_name FROM issues_old</query>
20
		<query driver="postgres7">SELECT SETVAL('issues_issue_id_seq', (SELECT MAX(issue_id) FROM issues)+1)</query>
20
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('issues', 'issue_id'), (SELECT MAX(issue_id) FROM issues)+1)</query>
21
		<query>INSERT INTO issue_settings (issue_id, setting_name, setting_value, setting_type, locale) SELECT issue_id, 'pub-id::publisher-id', public_issue_id, 'string', '' FROM issues_old WHERE public_issue_id IS NOT NULL AND public_issue_id != ''</query>
21
		<query>INSERT INTO issue_settings (issue_id, setting_name, setting_value, setting_type, locale) SELECT issue_id, 'pub-id::publisher-id', public_issue_id, 'string', '' FROM issues_old WHERE public_issue_id IS NOT NULL AND public_issue_id != ''</query>
22
		<query>DROP TABLE issues_old</query>
22
		<query>DROP TABLE issues_old</query>
23
	</sql>
23
	</sql>
(-)a/dbscripts/xml/upgrade/2.4.0_idupgrade_published_articles2.xml (-1 / +1 lines)
 Lines 17-23    Link Here 
17
		  - Migrate public IDs to settings tables.
17
		  - Migrate public IDs to settings tables.
18
		  -->
18
		  -->
19
		<query>INSERT INTO published_articles (published_article_id, article_id, issue_id, date_published, seq, views, access_status) SELECT pub_id, article_id, issue_id, date_published, seq, views, access_status FROM published_articles_old</query>
19
		<query>INSERT INTO published_articles (published_article_id, article_id, issue_id, date_published, seq, views, access_status) SELECT pub_id, article_id, issue_id, date_published, seq, views, access_status FROM published_articles_old</query>
20
		<query driver="postgres7">SELECT SETVAL('published_articles_published_article_id_seq', (SELECT MAX(published_article_id) FROM published_articles)+1)</query>
20
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('published_articles', 'published_article_id'), (SELECT MAX(published_article_id) FROM published_articles)+1)</query>
21
		<query>INSERT INTO article_settings (article_id, setting_name, setting_value, setting_type, locale) SELECT article_id, 'pub-id::publisher-id', public_article_id, 'string', '' FROM published_articles_old</query>
21
		<query>INSERT INTO article_settings (article_id, setting_name, setting_value, setting_type, locale) SELECT article_id, 'pub-id::publisher-id', public_article_id, 'string', '' FROM published_articles_old</query>
22
		<query>DROP TABLE published_articles_old</query>
22
		<query>DROP TABLE published_articles_old</query>
23
	</sql>
23
	</sql>
(-)a/dbscripts/xml/upgrade/2.4.0_idupgrade_supp_files2.xml (-1 / +1 lines)
 Lines 17-23    Link Here 
17
		  - Migrate public IDs to settings tables.
17
		  - Migrate public IDs to settings tables.
18
		  -->
18
		  -->
19
		<query>INSERT INTO article_supplementary_files (supp_id, file_id, article_id, type, language, date_created, show_reviewers, date_submitted, seq) SELECT supp_id, file_id, article_id, type, language, date_created, show_reviewers, date_submitted, seq FROM article_supp_files_old</query>
19
		<query>INSERT INTO article_supplementary_files (supp_id, file_id, article_id, type, language, date_created, show_reviewers, date_submitted, seq) SELECT supp_id, file_id, article_id, type, language, date_created, show_reviewers, date_submitted, seq FROM article_supp_files_old</query>
20
		<query driver="postgres7">SELECT SETVAL('article_supplementary_files_supp_id_seq', (SELECT MAX(supp_id) FROM article_supplementary_files)+1)</query>
20
		<query driver="postgres7">SELECT SETVAL(pg_get_serial_sequence('article_supplementary_files', 'supp_id'), (SELECT MAX(supp_id) FROM article_supplementary_files)+1)</query>
21
		<query>INSERT INTO article_supp_file_settings (supp_id, setting_name, setting_value, setting_type, locale) SELECT supp_id, 'pub-id::publisher-id', public_supp_file_id, 'string', '' FROM article_supp_files_old</query>
21
		<query>INSERT INTO article_supp_file_settings (supp_id, setting_name, setting_value, setting_type, locale) SELECT supp_id, 'pub-id::publisher-id', public_supp_file_id, 'string', '' FROM article_supp_files_old</query>
22
		<query>DROP TABLE article_supp_files_old</query>
22
		<query>DROP TABLE article_supp_files_old</query>
23
	</sql>
23
	</sql>
(-)a/dbscripts/xml/upgrade/2.4.0_preupdate_reviewrounds.xml (-4 / +1 lines)
 Lines 18-27    Link Here 
18
		</query>
18
		</query>
19
		<query driver="postgres7">
19
		<query driver="postgres7">
20
			DROP INDEX review_rounds_pkey;
20
			DROP INDEX review_rounds_pkey;
21
			ALTER TABLE review_rounds ADD review_round_id INT;
21
			ALTER TABLE review_rounds ADD review_round_id SERIAL;
22
			CREATE SEQUENCE review_rounds_review_round_id_seq_tmp;<!-- _tmp to avoid name clash when table is recreated by ADODB -->
23
			ALTER TABLE review_rounds ALTER COLUMN review_round_id SET DEFAULT NEXTVAL('review_rounds_review_round_id_seq_tmp');
24
			UPDATE review_rounds SET review_round_id = NEXTVAL('review_rounds_review_round_id_seq_tmp');
25
			ALTER TABLE review_rounds ADD PRIMARY KEY (review_round_id);
22
			ALTER TABLE review_rounds ADD PRIMARY KEY (review_round_id);
26
		</query>
23
		</query>
27
	</sql>
24
	</sql>
(-)a/lib/pkp/lib/adodb/drivers/adodb-postgres64.inc.php (-30 / +37 lines)
 Lines 139-179   function IfNull( $field, $ifNull ) Link Here 
139
	// get the last id - never tested
139
	// get the last id - never tested
140
	function pg_insert_id($tablename,$fieldname)
140
	function pg_insert_id($tablename,$fieldname)
141
	{
141
	{
142
		$result=pg_exec($this->_connectionID, "SELECT last_value FROM ${tablename}_${fieldname}_seq");
142
		// Use implementation in PO_Insert_ID instead.
143
		if ($result) {
143
		// This function is deprecated.
144
			$arr = @pg_fetch_row($result,0);
144
		return $this->PO_Insert_ID($tablename, $fieldname);
145
			pg_freeresult($result);
146
			if (isset($arr[0])) return $arr[0];
147
		}
148
		return false;
149
	}
145
	}
150
	
146
	
151
/* Warning from http://www.php.net/manual/function.pg-getlastoid.php:
147
	/**
152
Using a OID as a unique identifier is not generally wise. 
148
	 * Get the last inserted ID for the specified table and column.
153
Unless you are very careful, you might end up with a tuple having 
149
	 * @param $table string Optional table name
154
a different OID if a database must be reloaded. */
150
	 * @param $id string Optional column name
155
	function _insertid($table,$column)
151
	 */
156
	{
152
	function _insertid($table,$column) {
157
		if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false;
153
		// If no table is specified, we can use LASTVAL()
158
		$oid = pg_getlastoid($this->_resultid);
154
		if ($table === '') {
159
		// to really return the id, we need the table and column-name, else we can only return the oid != id
155
			$result = pg_exec('SELECT LASTVAL()');
160
		return empty($table) || empty($column) ? $oid : $this->GetOne("SELECT $column FROM $table WHERE oid=".(int)$oid);
156
			$row = pg_fetch_row($result, 0);
161
	}
157
			return $row[0];
158
		}
162
159
163
	// Added 2004-06-27 by Kevin Jamieson (http://pkp.sfu.ca/)
160
		// If this is PostgreSQL >= 8.0 and a column is specified, use pg_get_serial_sequence
164
	// Insert_ID function that returns the actual field value instead of the OID
161
		$info = $this->ServerInfo();
165
	function PO_Insert_ID($table="", $id="") {
162
		if ($column !== '' && $info['version'] >= 8.0) {
166
		if (!empty($table) && !empty($id)) {
163
			$result = pg_exec("SELECT CURRVAL(pg_get_serial_sequence('$table', '$column'))");
167
			$result = @pg_exec("SELECT CURRVAL('{$table}_{$id}_seq')");
164
			$row = pg_fetch_row($result, 0);
168
			if ($result) {
165
			return $row[0];
169
				$row = @pg_fetch_row($result, 0);
166
		}
170
				if (isset($row[0])) {
167
171
					return $row[0];
168
		// Try to identify the sequence name from the column descriptions
172
				}
169
		foreach($this->MetaColumns($table) as $fld) {
170
			if (
171
				isset($fld->primary_key) && $fld->primary_key && $fld->has_default &&
172
				preg_match("/nextval\('(?:[^']+\.)*([^']+)'::(text|regclass)\)/",$fld->default_value,$matches) &&
173
				($fld->name == $column || $column == '') // Field matches specified value or none given
174
			) {
175
				$result = pg_exec('SELECT CURRVAL(\'' . $matches[1] . '\')');
176
				$row = pg_fetch_row($result, 0);
177
assert($row[0] != 0);
178
				return $row[0];
173
			}
179
			}
174
		}
180
		}
175
		
181
176
		return $this->_insertid($table, $id);
182
		// Unable to identify sequence to use.
183
		assert(false);
177
	}
184
	}
178
185
179
// I get this error with PHP before 4.0.6 - jlim
186
// I get this error with PHP before 4.0.6 - jlim

Return to bug 8252