📄 databasescript.java
字号:
View v = (View) tTable.elementAt(i); if (bDrop) { addRow(r, "DROP VIEW " + v.getName().name); } a = new StringBuffer(128); a.append("CREATE "); a.append("VIEW "); a.append(v.getName().statementName); a.append(" AS "); a.append(v.getStatement()); addRow(r, a.toString()); } } for (int i = 0, tSize = tTable.size(); i < tSize; i++) { Table t = (Table) tTable.elementAt(i); if (bInsert == false || t.isTemp() || t.isView() || (t.isCached &&!bCached) || (t.isText() && t.isDataReadOnly())) { continue; } Index primary = t.getPrimaryIndex(); Node x = primary.first(); boolean integrity = true; if (x != null) { integrity = false; // fredt@users - comment - is this necessary? // tables are in order and no rows break FK constraints // addRow(r, "SET REFERENTIAL_INTEGRITY FALSE"); } while (x != null) { addRow(r, t.getInsertStatement(x.getData())); x = primary.next(x); }/* if (!integrity) { addRow(r, "SET REFERENTIAL_INTEGRITY TRUE"); }*/// fredt@users 20020221 - patch 513005 by sqlbob@users (RMP) if (t.isDataReadOnly()) { a = new StringBuffer("SET TABLE "); a.append(t.getName().statementName); a.append(" READONLY TRUE"); addRow(r, a.toString()); } } return r; } static String getIndexRootsDDL(Table t) throws SQLException { StringBuffer a = new StringBuffer(128); a.append("SET TABLE "); a.append(t.getName().statementName); a.append(" INDEX '"); a.append(t.getIndexRoots()); a.append('\''); return a.toString(); } static void getTableDDL(Database dDatabase, Table t, int i, Vector forwardFK, Vector forwardFKSource, StringBuffer a) throws SQLException { a.append("CREATE ");// fredt@users 20020221 - patch 513005 by sqlbob@users (RMP)// required for Text Table support if (t.isText()) { a.append("TEXT "); } else if (t.isCached()) { a.append("CACHED "); } a.append("TABLE "); a.append(t.getName().statementName); a.append('('); int columns = t.getColumnCount(); Index pki = t.getIndex(0); int pk[] = pki.getColumns(); for (int j = 0; j < columns; j++) { Column column = t.getColumn(j); String colname = column.columnName.statementName; a.append(colname); a.append(' ');// fredt@users 20020130 - patch 491987 by jimbag@users String sType = Column.getTypeString(column.getType()); a.append(sType); // append the size and scale if > 0 if (column.getSize() > 0) { a.append('('); a.append(column.getSize()); if (column.getScale() > 0) { a.append(','); a.append(column.getScale()); } a.append(')'); }// fredt@users 20020218 - patch 1.7.0 by fredt - DEFAULT keyword if (column.getDefaultString() != null) { a.append(" DEFAULT "); a.append(Column.createSQLString(column.getDefaultString())); } if (!column.isNullable()) { a.append(" NOT NULL"); } if (j == t.getIdentityColumn()) { a.append(" IDENTITY"); } if ((pk.length == 1) && (j == pk[0])) { a.append(" PRIMARY KEY"); } if (j < columns - 1) { a.append(','); } } if (pk.length > 1) { a.append(",CONSTRAINT "); a.append(pki.getName().statementName); a.append(" PRIMARY KEY"); getColumnList(t, pk, pk.length, a); } Vector v = t.getConstraints(); for (int j = 0, vSize = v.size(); j < vSize; j++) { Constraint c = (Constraint) v.elementAt(j); if (c.getType() == Constraint.UNIQUE) { a.append(",CONSTRAINT "); a.append(c.getName().statementName); a.append(" UNIQUE"); int col[] = c.getMainColumns(); getColumnList(c.getMain(), col, col.length, a); } else if (c.getType() == Constraint.FOREIGN_KEY) { // forward referencing FK Table maintable = c.getMain(); int maintableindex = dDatabase.getTableIndex(maintable); if (maintableindex > i) { if (i >= forwardFKSource.size()) { forwardFKSource.setSize(i + 1); } forwardFKSource.setElementAt(c, i); forwardFK.addElement(c); } else { a.append(','); getFKStatement(c, a); } } } a.append(')'); } /** * Method declaration * * * @param t * * @return */ static String getDataSource(Table t) throws SQLException { String dataSource = t.getDataSource(); if (dataSource == null) { return null; } boolean isDesc = t.isDescDataSource(); StringBuffer a = new StringBuffer(128); a.append("SET TABLE "); a.append(t.getName().statementName); a.append(" SOURCE \""); a.append(dataSource); a.append('"'); if (isDesc) { a.append(" DESC"); } return a.toString(); } /** * Method declaration * * * @param t * @param col * @param len * @param a * * @return */ private static void getColumnList(Table t, int col[], int len, StringBuffer a) { a.append('('); for (int i = 0; i < len; i++) { a.append(t.getColumn(col[i]).columnName.statementName); if (i < len - 1) { a.append(','); } } a.append(')'); } /** * Method declaration * * * @param c * @param a * * @return */ private static void getFKStatement(Constraint c, StringBuffer a) { a.append("CONSTRAINT "); a.append(c.getName().statementName); a.append(" FOREIGN KEY"); int col[] = c.getRefColumns(); getColumnList(c.getRef(), col, col.length, a); a.append(" REFERENCES "); a.append(c.getMain().getName().statementName); col = c.getMainColumns(); getColumnList(c.getMain(), col, col.length, a); if (c.isCascade()) { a.append(" ON DELETE CASCADE"); } } /** * Method declaration * * * @param r * @param sql */ private static void addRow(Result r, String sql) { String s[] = new String[1]; s[0] = sql; r.add(s); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -