From 09ac6097a6a4ca03b95cd84cefbe936462061d09 Mon Sep 17 00:00:00 2001 From: mdb Date: Fri, 29 Sep 2006 01:28:53 +0000 Subject: [PATCH] Always update then insert in case for whatever reason the zeroth schema version is not one (like for ItemRecord). git-svn-id: https://samskivert.googlecode.com/svn/trunk@1933 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/jdbc/depot/DepotMarshaller.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java index 5617b900..5aef6b2d 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java +++ b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java @@ -540,14 +540,16 @@ public class DepotMarshaller protected void updateVersion (Connection conn, int version) throws SQLException { - String query = (version == 1) ? - "insert into " + SCHEMA_VERSION_TABLE + - " values('" + getTableName() + "', " + version + ")" : - "update " + SCHEMA_VERSION_TABLE + " set version = " + version + + String update = "update " + SCHEMA_VERSION_TABLE + + " set version = " + version + " where persistentClass = '" + getTableName() + "'"; + String insert = "insert into " + SCHEMA_VERSION_TABLE + + " values('" + getTableName() + "', " + version + ")"; Statement stmt = conn.createStatement(); try { - stmt.executeUpdate(query); + if (stmt.executeUpdate(update) == 0) { + stmt.executeUpdate(insert); + } } finally { stmt.close(); }