Changeset 546724
- Timestamp:
- 05/20/2012 09:57:33 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
postgresql-for-wordpress/trunk/pg4wp/driver_pgsql.php
r546689 r546724 145 145 } 146 146 147 function wpsql_insert_id($ table)147 function wpsql_insert_id($lnk = NULL) 148 148 { 149 149 global $wpdb; 150 150 $ins_field = $GLOBALS['pg4wp_ins_field']; 151 152 $tbls = split("\n", $GLOBALS['pg4wp_ins_table']); // Workaround for bad tablename 153 $t = $tbls[0] . '_seq'; 154 155 if( in_array( $t, array( '_seq', $wpdb->prefix.'term_relationships_seq'))) 156 return 0; 157 158 if( $ins_field == '"cat_ID"' || $ins_field == 'rel_id' || $ins_field == 'term_id') 159 $sql = "SELECT MAX($ins_field) FROM ".$tbls[0]; 151 $table = $GLOBALS['pg4wp_ins_table']; 152 153 $seq = $table . '_seq'; 154 155 // Table 'term_relationships' doesn't have a sequence 156 if( $table == $wpdb->term_relationships || 'post_author' == $ins_field) 157 { 158 $sql = 'NO QUERY'; 159 $data = 0; 160 } 160 161 else 161 $sql = "SELECT CURRVAL('$t')"; 162 163 $res = pg_query($sql); 164 $data = pg_fetch_result($res, 0, 0); 162 { 163 $sql = "SELECT CURRVAL('$seq')"; 164 165 $res = pg_query($sql); 166 if( false !== $res) 167 $data = pg_fetch_result($res, 0, 0); 168 elseif( PG4WP_DEBUG || PG4WP_ERROR_LOG) 169 { 170 if( PG4WP_DEBUG) 171 $lastq = $GLOBALS['pg4wp_last_insert']; 172 else 173 $lastq = 'UNKNOWN'; 174 $log = '['.microtime(true)."] wpsql_insert_id() was called with '$table' and '$ins_field'". 175 " and generated an error. The latest INSERT query was :\n'$lastq'\n"; 176 error_log( $log, 3, PG4WP_LOG.'pg4wp_errors.log'); 177 } 178 } 165 179 if( PG4WP_DEBUG && $sql) 166 error_log( '['.microtime(true)."] Getting inserted ID for '$t' : $sql => $data\n", 3, PG4WP_LOG.'pg4wp_insertid.log'); 180 error_log( '['.microtime(true)."] Getting inserted ID for '$table' ('$ins_field') : $sql => $data\n", 3, PG4WP_LOG.'pg4wp_insertid.log'); 181 167 182 return $data; 168 183 } … … 424 439 $sql = str_replace( 'IN ()', 'IN (NULL)', $sql); 425 440 441 // Put back the end of the query if it was separated 442 $sql .= $end; 443 426 444 // For insert ID catching 427 445 if( $logto == 'INSERT') … … 437 455 $GLOBALS['pg4wp_ins_field'] = trim($match_list[4],' () '); 438 456 } 439 } 440 441 // Put back the end of the query if it was separated 442 $sql .= $end; 457 if( PG4WP_DEBUG) 458 $GLOBALS['pg4wp_last_insert'] = $sql; 459 } 443 460 444 461 // Correct quoting for PostgreSQL 9.1+ compatibility
Note: See TracChangeset
for help on using the changeset viewer.