Package org.tmatesoft.sqljet.core.schema

Examples of org.tmatesoft.sqljet.core.schema.ISqlJetColumnDef


                if (constraint instanceof ISqlJetTablePrimaryKey) {
                    boolean b = false;
                    final ISqlJetTablePrimaryKey pk = (ISqlJetTablePrimaryKey) constraint;
                    if (pk.getColumns().size() == 1) {
                        final String n = pk.getColumns().get(0);
                        final ISqlJetColumnDef c = tableDef.getColumn(n);
                        b = c != null && c.hasExactlyIntegerType();
                    }
                    if (!b) {
                        createAutoIndex(schemaTable, tableName, generateAutoIndexName(tableName, ++i));
                    }
                } else if (constraint instanceof ISqlJetTableUnique) {
View Full Code Here


    private ISqlJetTableDef alterTableSafe(final SqlJetAlterTableDef alterTableDef) throws SqlJetException {

        assert (null != alterTableDef);
        String tableName = alterTableDef.getTableName();
        String newTableName = alterTableDef.getNewTableName();
        ISqlJetColumnDef newColumnDef = alterTableDef.getNewColumnDef();

        if (null == tableName) {
            throw new SqlJetException(SqlJetErrorCode.MISUSE, "Table name isn't defined");
        }

        if (null == newTableName && null == newColumnDef) {
            throw new SqlJetException(SqlJetErrorCode.MISUSE, "Not defined any altering");
        }

        boolean renameTable = false;
        if (null != newTableName) {
            renameTable = true;
        } else {
            newTableName = tableName;
        }

        if (renameTable && tableDefs.containsKey(newTableName)) {
            throw new SqlJetException(SqlJetErrorCode.MISUSE,
                    String.format("Table \"%s\" already exists", newTableName));
        }

        final SqlJetTableDef tableDef = (SqlJetTableDef) tableDefs.get(tableName);
        if (null == tableDef) {
            throw new SqlJetException(SqlJetErrorCode.MISUSE, String.format("Table \"%s\" not found", tableName));
        }

        List<ISqlJetColumnDef> columns = tableDef.getColumns();
        if (null != newColumnDef) {

            final String fieldName = newColumnDef.getName();
            if (tableDef.getColumn(fieldName) != null) {
                throw new SqlJetException(SqlJetErrorCode.MISUSE, String.format(
                        "Field \"%s\" already exists in table \"%s\"", fieldName, tableName));
            }

            final List<ISqlJetColumnConstraint> constraints = newColumnDef.getConstraints();
            if (null != constraints && 0 != constraints.size()) {
                boolean notNull = false;
                boolean defaultValue = false;
                for (final ISqlJetColumnConstraint constraint : constraints) {
                    if (constraint instanceof ISqlJetColumnNotNull) {
View Full Code Here

                SqlJetTablePrimaryKey pk = (SqlJetTablePrimaryKey) constraint;
                assert primaryKeyColumns.isEmpty();
                primaryKeyColumns.addAll(pk.getColumns());
                if (pk.getColumns().size() == 1) {
                    final String n = pk.getColumns().get(0);
                    final ISqlJetColumnDef c = getColumn(n);
                    if (null == c) {
                        throw new SqlJetException(SqlJetErrorCode.ERROR, "Wrong column '" + n + "' in PRIMARY KEY");
                    } else if (c.hasExactlyIntegerType()) {
                        rowIdPrimaryKeyColumnName = n;
                        rowIdPrimaryKeyColumnIndex = getColumnNumber(n);
                        rowIdPrimaryKey = true;
                        b = true;
                    }
View Full Code Here

     */
    private Object[] getDefaults() throws SqlJetException {
        final Object[] row = new Object[tableDef.getColumns().size()];
        if (btree.getDb().getOptions().getFileFormat() > 2) {
            for (int i = 0; i < tableDef.getColumns().size(); i++) {
                final ISqlJetColumnDef column = tableDef.getColumns().get(i);
                for (final ISqlJetColumnConstraint constraint : column.getConstraints()) {
                    if (constraint instanceof ISqlJetColumnDefault) {
                        final ISqlJetColumnDefault d = (ISqlJetColumnDefault) constraint;
                        row[i] = d.getExpression().getValue();
                    }
                }
View Full Code Here

    }

    public void testSchema() throws SqlJetException {
        String sql = "create table t (c1 int primary key, c2 varchar, c3 super double, c4 short unique, c5 blob, c6)";
        ISqlJetTableDef table = new SqlJetTableDef(parse(sql), 0);
        ISqlJetColumnDef c1 = table.getColumn("c1");
        assertEquals(SqlJetTypeAffinity.INTEGER, c1.getTypeAffinity());
        ISqlJetColumnDef c2 = table.getColumn("c2");
        assertEquals(SqlJetTypeAffinity.TEXT, c2.getTypeAffinity());
        ISqlJetColumnDef c3 = table.getColumn("c3");
        assertEquals(SqlJetTypeAffinity.REAL, c3.getTypeAffinity());
        ISqlJetColumnDef c4 = table.getColumn("c4");
        assertEquals(SqlJetTypeAffinity.NUMERIC, c4.getTypeAffinity());
        ISqlJetColumnDef c5 = table.getColumn("c5");
        assertEquals(SqlJetTypeAffinity.NONE, c5.getTypeAffinity());
        ISqlJetColumnDef c6 = table.getColumn("c6");
        assertEquals(SqlJetTypeAffinity.NONE, c6.getTypeAffinity());
    }
View Full Code Here

TOP

Related Classes of org.tmatesoft.sqljet.core.schema.ISqlJetColumnDef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.