Refactor the version handling
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Pg.pm
index 1b5e6d8..4428b1f 100644 (file)
@@ -16,10 +16,13 @@ use Context::Preserve ();
 warn __PACKAGE__.": DBD::Pg 2.9.2 or greater is strongly recommended\n"
   if ($DBD::Pg::VERSION < 2.009002);  # pg uses (used?) version::qv()
 
-sub can_insert_returning {
-  # FIXME !!!
-  # pg before 8.2 doesn't support this, need to check version
-  return 1;
+sub _supports_insert_returning {
+  my $self = shift;
+
+  return 1
+    if $self->_server_info->{normalized_dbms_version} >= 8.002;
+
+  return 0;
 }
 
 sub with_deferred_fk_checks {
@@ -37,6 +40,7 @@ sub with_deferred_fk_checks {
     after => sub { $txn_scope_guard->commit });
 }
 
+# only used when INSERT ... RETURNING is disabled
 sub last_insert_id {
   my ($self,$source,@cols) = @_;
 
@@ -62,8 +66,7 @@ sub _sequence_fetch {
   $self->throw_exception('No sequence to fetch') unless $sequence;
 
   my ($val) = $self->_get_dbh->selectrow_array(
-    sprintf "select $function('%s')",
-      $sequence
+    sprintf ("select %s('%s')", $function, $sequence)
   );
 
   return $val;