Changeset 4099
- Timestamp:
- Jan 23, 2008, 4:37:23 PM (15 years ago)
- Location:
- trunk/src/core/net/sf/basedb/core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/HibernateUtil.java
r4034 r4099 575 575 tx = HibernateUtil.newTransaction(session); 576 576 Connection connection = HibernateUtil.getConnection(session); 577 578 if (!tableExists(table.getTableName(db), connection)) 577 String tableName = table.getTableName(db); 578 579 if (!tableExists(tableName, connection)) 579 580 { 580 581 Table hibernateTable = newDynamicMapping(db, table); 581 582 Dialect dialect = getDialect(); 582 String dynamicCatalog = quote(Application.getDynamicCatalog()); 583 String dynamicSchema = quote(Application.getDynamicSchema()); 584 585 String sql = hibernateTable.sqlCreateString(dialect, null, dynamicCatalog, dynamicSchema); 583 String dynamicCatalog = Application.getDynamicCatalog(); 584 String quotedCatalog = quote(dynamicCatalog); 585 String dynamicSchema = Application.getDynamicSchema(); 586 String quotedSchema = quote(dynamicSchema); 587 588 String sql = hibernateTable.sqlCreateString(dialect, null, quotedCatalog, quotedSchema); 589 sql = dbEngine.makeSafeCreateTable(sql, dynamicCatalog, dynamicSchema, tableName); 590 System.out.println(sql); 586 591 logSql.debug(sql); 587 592 … … 593 598 { 594 599 Index ii = (Index)i.next(); 595 sql = ii.sqlCreateString(dialect, null, dynamicCatalog, dynamicSchema);600 sql = ii.sqlCreateString(dialect, null, quotedCatalog, quotedSchema); 596 601 logSql.debug(sql); 597 602 s.executeUpdate(sql); -
trunk/src/core/net/sf/basedb/core/dbengine/AbstractDbEngine.java
r3675 r4099 53 53 ------------------------------------------- 54 54 */ 55 /** 56 Return the SQL unmodified. 57 @since 2.6 58 */ 59 public String makeSafeCreateTable(String sql, String catalog, String schema, String table) 60 { 61 return sql; 62 } 55 63 /** 56 64 Most databases doesn't. Any more than Oracle? -
trunk/src/core/net/sf/basedb/core/dbengine/DbEngine.java
r3675 r4099 135 135 136 136 /** 137 Create a "safe" CREATE TABLE query string that will not fail if the table already 138 exists. Implementors should inject proper SQL code in a way that is supported in the 139 underlying database. The MySQL engine, for example, replaces CREATE TABLE with 140 CREATE TABLE IF NOT EXISTS. If the underlying database doesn't support this kind 141 of check the original SQL should be returned umodified. 142 143 @param sql The original SQL 144 @param catalog 145 @param catalog The name of the catalog (database) where the table is 146 being create, or null if it is located in the current catalog 147 @param schema The name of the schema where the table is being created, or 148 null if is located in the current schema 149 @param table The name of the table that is being created 150 @return The modified or unmodified SQL statement 151 @since 2.6 152 */ 153 public String makeSafeCreateTable(String sql, String catalog, String schema, String table); 154 155 /** 137 156 If the database does case sensitive or case insensitive string 138 157 comparison in expressions. -
trunk/src/core/net/sf/basedb/core/dbengine/MySQLEngine.java
r3675 r4099 25 25 26 26 import java.util.Set; 27 import java.util.regex.Matcher; 28 import java.util.regex.Pattern; 27 29 28 30 /** … … 123 125 124 126 /** 127 Replace CREATE TABLE with CREATE TABLE IF NOT EXISTS... 128 @since 2.6 129 */ 130 public String makeSafeCreateTable(String sql, String catalog, String schema, String table) 131 { 132 Pattern p = Pattern.compile("CREATE TABLE", Pattern.CASE_INSENSITIVE); 133 Matcher m = p.matcher(sql); 134 sql = m.replaceFirst("CREATE TABLE IF NOT EXISTS"); 135 return sql; 136 } 137 138 /** 125 139 Returns TRUE. 126 140 @since 2.4
Note: See TracChangeset
for help on using the changeset viewer.