提交 1ce2de09 authored 作者: Sergi Vladykin's avatar Sergi Vladykin

Fixes and improvements in PG protocol support. New method getCommandType() was…

Fixes and improvements in PG protocol support. New method getCommandType() was added to CommandInterface to return the type of current SQL statement.
上级 76ba1ff8
......@@ -94,4 +94,8 @@ public class CommandContainer extends Command {
return prepared.isCacheable();
}
public int getCommandType() {
return prepared.getType();
}
}
......@@ -15,6 +15,445 @@ import org.h2.result.ResultInterface;
*/
public interface CommandInterface {
/**
* The type for unknown statement.
*/
int UNKNOWN = 0;
// ddl operations
/**
* The type of a ALTER INDEX RENAME statement.
*/
int ALTER_INDEX_RENAME = 1;
/**
* The type of a ALTER SCHEMA RENAME statement.
*/
int ALTER_SCHEMA_RENAME = 2;
/**
* The type of a ALTER TABLE ADD CHECK statement.
*/
int ALTER_TABLE_ADD_CONSTRAINT_CHECK = 3;
/**
* The type of a ALTER TABLE ADD UNIQUE statement.
*/
int ALTER_TABLE_ADD_CONSTRAINT_UNIQUE = 4;
/**
* The type of a ALTER TABLE ADD FOREIGN KEY statement.
*/
int ALTER_TABLE_ADD_CONSTRAINT_REFERENTIAL = 5;
/**
* The type of a ALTER TABLE ADD PRIMARY KEY statement.
*/
int ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY = 6;
/**
* The type of a ALTER TABLE ADD statement.
*/
int ALTER_TABLE_ADD_COLUMN = 7;
/**
* The type of a ALTER TABLE ALTER COLUMN SET NOT NULL statement.
*/
int ALTER_TABLE_ALTER_COLUMN_NOT_NULL = 8;
/**
* The type of a ALTER TABLE ALTER COLUMN SET NULL statement.
*/
int ALTER_TABLE_ALTER_COLUMN_NULL = 9;
/**
* The type of a ALTER TABLE ALTER COLUMN SET DEFAULT statement.
*/
int ALTER_TABLE_ALTER_COLUMN_DEFAULT = 10;
/**
* The type of an ALTER TABLE ALTER COLUMN statement that changes the column
* data type.
*/
int ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE = 11;
/**
* The type of a ALTER TABLE DROP COLUMN statement.
*/
int ALTER_TABLE_DROP_COLUMN = 12;
/**
* The type of a ALTER TABLE ALTER COLUMN SELECTIVITY statement.
*/
int ALTER_TABLE_ALTER_COLUMN_SELECTIVITY = 13;
/**
* The type of a ALTER TABLE DROP CONSTRAINT statement.
*/
int ALTER_TABLE_DROP_CONSTRAINT = 14;
/**
* The type of a ALTER TABLE RENAME statement.
*/
int ALTER_TABLE_RENAME = 15;
/**
* The type of a ALTER TABLE ALTER COLUMN RENAME statement.
*/
int ALTER_TABLE_ALTER_COLUMN_RENAME = 16;
/**
* The type of a ALTER USER ADMIN statement.
*/
int ALTER_USER_ADMIN = 17;
/**
* The type of a ALTER USER RENAME statement.
*/
int ALTER_USER_RENAME = 18;
/**
* The type of a ALTER USER SET PASSWORD statement.
*/
int ALTER_USER_SET_PASSWORD = 19;
/**
* The type of a ALTER VIEW statement.
*/
int ALTER_VIEW = 20;
/**
* The type of a ANALYZE statement.
*/
int ANALYZE = 21;
/**
* The type of a CREATE AGGREGATE statement.
*/
int CREATE_AGGREGATE = 22;
/**
* The type of a CREATE CONSTANT statement.
*/
int CREATE_CONSTANT = 23;
/**
* The type of a CREATE ALIAS statement.
*/
int CREATE_ALIAS = 24;
/**
* The type of a CREATE INDEX statement.
*/
int CREATE_INDEX = 25;
/**
* The type of a CREATE LINKED TABLE statement.
*/
int CREATE_LINKED_TABLE = 26;
/**
* The type of a CREATE ROLE statement.
*/
int CREATE_ROLE = 27;
/**
* The type of a CREATE SCHEMA statement.
*/
int CREATE_SCHEMA = 28;
/**
* The type of a CREATE SEQUENCE statement.
*/
int CREATE_SEQUENCE = 29;
/**
* The type of a CREATE TABLE statement.
*/
int CREATE_TABLE = 30;
/**
* The type of a CREATE TRIGGER statement.
*/
int CREATE_TRIGGER = 31;
/**
* The type of a CREATE USER statement.
*/
int CREATE_USER = 32;
/**
* The type of a CREATE DOMAIN statement.
*/
int CREATE_DOMAIN = 33;
/**
* The type of a CREATE VIEW statement.
*/
int CREATE_VIEW = 34;
/**
* The type of a DEALLOCATE statement.
*/
int DEALLOCATE = 35;
/**
* The type of a DROP AGGREGATE statement.
*/
int DROP_AGGREGATE = 36;
/**
* The type of a DROP CONSTANT statement.
*/
int DROP_CONSTANT = 37;
/**
* The type of a DROP ALL OBJECTS statement.
*/
int DROP_ALL_OBJECTS = 38;
/**
* The type of a DROP ALIAS statement.
*/
int DROP_ALIAS = 39;
/**
* The type of a DROP INDEX statement.
*/
int DROP_INDEX = 40;
/**
* The type of a DROP ROLE statement.
*/
int DROP_ROLE = 41;
/**
* The type of a DROP SCHEMA statement.
*/
int DROP_SCHEMA = 42;
/**
* The type of a DROP SEQUENCE statement.
*/
int DROP_SEQUENCE = 43;
/**
* The type of a DROP TABLE statement.
*/
int DROP_TABLE = 44;
/**
* The type of a DROP TRIGGER statement.
*/
int DROP_TRIGGER = 45;
/**
* The type of a DROP USER statement.
*/
int DROP_USER = 46;
/**
* The type of a DROP DOMAIN statement.
*/
int DROP_DOMAIN = 47;
/**
* The type of a DROP VIEW statement.
*/
int DROP_VIEW = 48;
/**
* The type of a GRANT statement.
*/
int GRANT = 49;
/**
* The type of a REVOKE statement.
*/
int REVOKE = 50;
/**
* The type of a PREPARE statement.
*/
int PREPARE = 51;
/**
* The type of a COMMENT statement.
*/
int COMMENT = 52;
/**
* The type of a TRUNCATE TABLE statement.
*/
int TRUNCATE_TABLE = 53;
// dml operations
/**
* The type of a ALTER SEQUENCE statement.
*/
int ALTER_SEQUENCE = 54;
/**
* The type of a ALTER TABLE SET REFERENTIAL_INTEGRITY statement.
*/
int ALTER_TABLE_SET_REFERENTIAL_INTEGRITY = 55;
/**
* The type of a BACKUP statement.
*/
int BACKUP = 56;
/**
* The type of a CALL statement.
*/
int CALL = 57;
/**
* The type of a DELETE statement.
*/
int DELETE = 58;
/**
* The type of a EXECUTE statement.
*/
int EXECUTE = 59;
/**
* The type of a EXPLAIN statement.
*/
int EXPLAIN = 60;
/**
* The type of a INSERT statement.
*/
int INSERT = 61;
/**
* The type of a MERGE statement.
*/
int MERGE = 62;
/**
* The type of a no operation statement.
*/
int NO_OPERATION = 63;
/**
* The type of a RUNSCRIPT statement.
*/
int RUNSCRIPT = 64;
/**
* The type of a SCRIPT statement.
*/
int SCRIPT = 65;
/**
* The type of a SELECT statement.
*/
int SELECT = 66;
/**
* The type of a SET statement.
*/
int SET = 67;
/**
* The type of a UPDATE statement.
*/
int UPDATE = 68;
// transaction commands
/**
* The type of a SET AUTOCOMMIT statement.
*/
int SET_AUTOCOMMIT_TRUE = 69;
/**
* The type of a SET AUTOCOMMIT statement.
*/
int SET_AUTOCOMMIT_FALSE = 70;
/**
* The type of a COMMIT statement.
*/
int COMMIT = 71;
/**
* The type of a ROLLBACK statement.
*/
int ROLLBACK = 72;
/**
* The type of a CHECKPOINT statement.
*/
int CHECKPOINT = 73;
/**
* The type of a SAVEPOINT statement.
*/
int SAVEPOINT = 74;
/**
* The type of a ROLLBACK TO SAVEPOINT statement.
*/
int ROLLBACK_TO_SAVEPOINT = 75;
/**
* The type of a CHECKPOINT SYNC statement.
*/
int CHECKPOINT_SYNC = 76;
/**
* The type of a PREPARE COMMIT statement.
*/
int PREPARE_COMMIT = 77;
/**
* The type of a COMMIT TRANSACTION statement.
*/
int COMMIT_TRANSACTION = 78;
/**
* The type of a ROLLBACK TRANSACTION statement.
*/
int ROLLBACK_TRANSACTION = 79;
/**
* The type of a SHUTDOWN statement.
*/
int SHUTDOWN = 80;
/**
* The type of a SHUTDOWN IMMEDIATELY statement.
*/
int SHUTDOWN_IMMEDIATELY = 81;
/**
* The type of a SHUTDOWN COMPACT statement.
*/
int SHUTDOWN_COMPACT = 82;
/**
* The type of a BEGIN {WORK|TRANSACTION} statement.
*/
int BEGIN = 83;
/**
* The type of a SHUTDOWN DEFRAG statement.
*/
int SHUTDOWN_DEFRAG = 84;
/**
* Get command type.
*
* @return one of the constants above
*/
int getCommandType();
/**
* Check if this is a query.
*
......
......@@ -65,4 +65,8 @@ public class CommandList extends Command {
return command.queryMeta();
}
public int getCommandType() {
return command.getCommandType();
}
}
......@@ -248,4 +248,8 @@ public class CommandRemote implements CommandInterface {
return TraceObject.toString(sql, getParameters());
}
public int getCommandType() {
return UNKNOWN;
}
}
......@@ -346,7 +346,7 @@ public class Parser {
case 'g':
case 'G':
if (readIf("GRANT")) {
c = parseGrantRevoke(GrantRevoke.GRANT);
c = parseGrantRevoke(CommandInterface.GRANT);
}
break;
case 'h':
......@@ -378,7 +378,7 @@ public class Parser {
if (readIf("ROLLBACK")) {
c = parseRollback();
} else if (readIf("REVOKE")) {
c = parseGrantRevoke(GrantRevoke.REVOKE);
c = parseGrantRevoke(CommandInterface.REVOKE);
} else if (readIf("RUNSCRIPT")) {
c = parseRunScript();
} else if (readIf("RELEASE")) {
......@@ -497,30 +497,30 @@ public class Parser {
if (!readIf("WORK")) {
readIf("TRANSACTION");
}
command = new TransactionCommand(session, TransactionCommand.BEGIN);
command = new TransactionCommand(session, CommandInterface.BEGIN);
return command;
}
private TransactionCommand parseCommit() {
TransactionCommand command;
if (readIf("TRANSACTION")) {
command = new TransactionCommand(session, TransactionCommand.COMMIT_TRANSACTION);
command = new TransactionCommand(session, CommandInterface.COMMIT_TRANSACTION);
command.setTransactionName(readUniqueIdentifier());
return command;
}
command = new TransactionCommand(session, TransactionCommand.COMMIT);
command = new TransactionCommand(session, CommandInterface.COMMIT);
readIf("WORK");
return command;
}
private TransactionCommand parseShutdown() {
int type = TransactionCommand.SHUTDOWN;
int type = CommandInterface.SHUTDOWN;
if (readIf("IMMEDIATELY")) {
type = TransactionCommand.SHUTDOWN_IMMEDIATELY;
type = CommandInterface.SHUTDOWN_IMMEDIATELY;
} else if (readIf("COMPACT")) {
type = TransactionCommand.SHUTDOWN_COMPACT;
type = CommandInterface.SHUTDOWN_COMPACT;
} else if (readIf("DEFRAG")) {
type = TransactionCommand.SHUTDOWN_DEFRAG;
type = CommandInterface.SHUTDOWN_DEFRAG;
} else {
readIf("SCRIPT");
}
......@@ -530,24 +530,24 @@ public class Parser {
private TransactionCommand parseRollback() {
TransactionCommand command;
if (readIf("TRANSACTION")) {
command = new TransactionCommand(session, TransactionCommand.ROLLBACK_TRANSACTION);
command = new TransactionCommand(session, CommandInterface.ROLLBACK_TRANSACTION);
command.setTransactionName(readUniqueIdentifier());
return command;
}
if (readIf("TO")) {
read("SAVEPOINT");
command = new TransactionCommand(session, TransactionCommand.ROLLBACK_TO_SAVEPOINT);
command = new TransactionCommand(session, CommandInterface.ROLLBACK_TO_SAVEPOINT);
command.setSavepointName(readUniqueIdentifier());
} else {
readIf("WORK");
command = new TransactionCommand(session, TransactionCommand.ROLLBACK);
command = new TransactionCommand(session, CommandInterface.ROLLBACK);
}
return command;
}
private Prepared parsePrepare() {
if (readIf("COMMIT")) {
TransactionCommand command = new TransactionCommand(session, TransactionCommand.PREPARE_COMMIT);
TransactionCommand command = new TransactionCommand(session, CommandInterface.PREPARE_COMMIT);
command.setTransactionName(readUniqueIdentifier());
return command;
}
......@@ -572,7 +572,7 @@ public class Parser {
}
private TransactionCommand parseSavepoint() {
TransactionCommand command = new TransactionCommand(session, TransactionCommand.SAVEPOINT);
TransactionCommand command = new TransactionCommand(session, CommandInterface.SAVEPOINT);
command.setSavepointName(readUniqueIdentifier());
return command;
}
......@@ -3746,7 +3746,7 @@ public class Parser {
} while (readIf(","));
}
}
if (operationType == GrantRevoke.GRANT) {
if (operationType == CommandInterface.GRANT) {
read("TO");
} else {
read("FROM");
......@@ -4059,9 +4059,9 @@ public class Parser {
private TransactionCommand parseCheckpoint() {
TransactionCommand command;
if (readIf("SYNC")) {
command = new TransactionCommand(session, TransactionCommand.CHECKPOINT_SYNC);
command = new TransactionCommand(session, CommandInterface.CHECKPOINT_SYNC);
} else {
command = new TransactionCommand(session, TransactionCommand.CHECKPOINT);
command = new TransactionCommand(session, CommandInterface.CHECKPOINT);
}
return command;
}
......@@ -4148,7 +4148,7 @@ public class Parser {
String userName = readUniqueIdentifier();
if (readIf("SET")) {
AlterUser command = new AlterUser(session);
command.setType(AlterUser.SET_PASSWORD);
command.setType(CommandInterface.ALTER_USER_SET_PASSWORD);
command.setUser(database.getUser(userName));
if (readIf("PASSWORD")) {
command.setPassword(readExpression());
......@@ -4163,14 +4163,14 @@ public class Parser {
} else if (readIf("RENAME")) {
read("TO");
AlterUser command = new AlterUser(session);
command.setType(AlterUser.RENAME);
command.setType(CommandInterface.ALTER_USER_RENAME);
command.setUser(database.getUser(userName));
String newName = readUniqueIdentifier();
command.setNewName(newName);
return command;
} else if (readIf("ADMIN")) {
AlterUser command = new AlterUser(session);
command.setType(AlterUser.ADMIN);
command.setType(CommandInterface.ALTER_USER_ADMIN);
User user = database.getUser(userName);
command.setUser(user);
if (readIf("TRUE")) {
......@@ -4201,7 +4201,7 @@ public class Parser {
} else if (readIf("AUTOCOMMIT")) {
readIfEqualOrTo();
boolean value = readBooleanSetting();
int setting = value ? TransactionCommand.AUTOCOMMIT_TRUE : TransactionCommand.AUTOCOMMIT_FALSE;
int setting = value ? CommandInterface.SET_AUTOCOMMIT_TRUE : CommandInterface.SET_AUTOCOMMIT_FALSE;
return new TransactionCommand(session, setting);
} else if (readIf("MVCC")) {
readIfEqualOrTo();
......@@ -4223,14 +4223,14 @@ public class Parser {
} else if (readIf("PASSWORD")) {
readIfEqualOrTo();
AlterUser command = new AlterUser(session);
command.setType(AlterUser.SET_PASSWORD);
command.setType(CommandInterface.ALTER_USER_SET_PASSWORD);
command.setUser(session.getUser());
command.setPassword(readExpression());
return command;
} else if (readIf("SALT")) {
readIfEqualOrTo();
AlterUser command = new AlterUser(session);
command.setType(AlterUser.SET_PASSWORD);
command.setType(CommandInterface.ALTER_USER_SET_PASSWORD);
command.setUser(session.getUser());
command.setSalt(readExpression());
read("HASH");
......@@ -4560,14 +4560,9 @@ public class Parser {
return parseAlterTableAddColumn(table);
} else if (readIf("SET")) {
read("REFERENTIAL_INTEGRITY");
int type;
if (readIf("TRUE")) {
type = AlterTableSet.REFERENTIAL_INTEGRITY_TRUE;
} else {
read("FALSE");
type = AlterTableSet.REFERENTIAL_INTEGRITY_FALSE;
}
AlterTableSet command = new AlterTableSet(session, table.getSchema(), type);
int type = CommandInterface.ALTER_TABLE_SET_REFERENTIAL_INTEGRITY;
boolean value = readBooleanSetting();
AlterTableSet command = new AlterTableSet(session, table.getSchema(), type, value);
command.setTableName(table.getName());
if (readIf("CHECK")) {
command.setCheckExisting(true);
......@@ -4601,7 +4596,7 @@ public class Parser {
} else {
readIf("COLUMN");
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setType(AlterTableAlterColumn.DROP);
command.setType(CommandInterface.ALTER_TABLE_DROP_COLUMN);
String columnName = readColumnIdentifier();
command.setTable(table);
command.setOldColumn(table.getColumn(columnName));
......@@ -4625,7 +4620,7 @@ public class Parser {
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table);
command.setOldColumn(column);
command.setType(AlterTableAlterColumn.DEFAULT);
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_DEFAULT);
command.setDefaultExpression(null);
return command;
}
......@@ -4634,7 +4629,7 @@ public class Parser {
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table);
command.setOldColumn(column);
command.setType(AlterTableAlterColumn.NULL);
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_NULL);
return command;
} else if (readIf("TYPE")) {
// PostgreSQL compatibility
......@@ -4649,15 +4644,15 @@ public class Parser {
command.setTable(table);
command.setOldColumn(column);
if (readIf("NULL")) {
command.setType(AlterTableAlterColumn.NULL);
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_NULL);
return command;
} else if (readIf("NOT")) {
read("NULL");
command.setType(AlterTableAlterColumn.NOT_NULL);
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_NOT_NULL);
return command;
} else if (readIf("DEFAULT")) {
Expression defaultExpression = readExpression();
command.setType(AlterTableAlterColumn.DEFAULT);
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_DEFAULT);
command.setDefaultExpression(defaultExpression);
return command;
}
......@@ -4671,7 +4666,7 @@ public class Parser {
} else if (readIf("SELECTIVITY")) {
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table);
command.setType(AlterTableAlterColumn.SELECTIVITY);
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_SELECTIVITY);
command.setOldColumn(column);
command.setSelectivity(readExpression());
return command;
......@@ -4686,7 +4681,7 @@ public class Parser {
Column newColumn = parseColumnForTable(columnName, column.isNullable());
AlterTableAlterColumn command = new AlterTableAlterColumn(session, table.getSchema());
command.setTable(table);
command.setType(AlterTableAlterColumn.CHANGE_TYPE);
command.setType(CommandInterface.ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE);
command.setOldColumn(column);
command.setNewColumn(newColumn);
return command;
......@@ -4696,7 +4691,7 @@ public class Parser {
readIf("COLUMN");
Schema schema = table.getSchema();
AlterTableAlterColumn command = new AlterTableAlterColumn(session, schema);
command.setType(AlterTableAlterColumn.ADD);
command.setType(CommandInterface.ALTER_TABLE_ADD_COLUMN);
command.setTable(table);
String columnName = readColumnIdentifier();
Column column = parseColumnForTable(columnName, true);
......@@ -4747,7 +4742,7 @@ public class Parser {
if (readIf("PRIMARY")) {
read("KEY");
AlterTableAddConstraint command = new AlterTableAddConstraint(session, schema, ifNotExists);
command.setType(AlterTableAddConstraint.PRIMARY_KEY);
command.setType(CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY);
command.setComment(comment);
command.setConstraintName(constraintName);
command.setTableName(tableName);
......@@ -4776,13 +4771,13 @@ public class Parser {
AlterTableAddConstraint command;
if (readIf("CHECK")) {
command = new AlterTableAddConstraint(session, schema, ifNotExists);
command.setType(AlterTableAddConstraint.CHECK);
command.setType(CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_CHECK);
command.setCheckExpression(readExpression());
} else if (readIf("UNIQUE")) {
readIf("KEY");
readIf("INDEX");
command = new AlterTableAddConstraint(session, schema, ifNotExists);
command.setType(AlterTableAddConstraint.UNIQUE);
command.setType(CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_UNIQUE);
if (!readIf("(")) {
constraintName = readUniqueIdentifier();
read("(");
......@@ -4794,7 +4789,7 @@ public class Parser {
}
} else if (readIf("FOREIGN")) {
command = new AlterTableAddConstraint(session, schema, ifNotExists);
command.setType(AlterTableAddConstraint.REFERENTIAL);
command.setType(CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_REFERENTIAL);
read("KEY");
read("(");
command.setIndexColumns(parseIndexColumnList());
......@@ -4925,7 +4920,7 @@ public class Parser {
IndexColumn[] cols = { new IndexColumn() };
cols[0].columnName = column.getName();
AlterTableAddConstraint pk = new AlterTableAddConstraint(session, schema, false);
pk.setType(AlterTableAddConstraint.PRIMARY_KEY);
pk.setType(CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY);
pk.setTableName(tableName);
pk.setIndexColumns(cols);
command.addConstraintCommand(pk);
......@@ -4942,7 +4937,7 @@ public class Parser {
cols[0].columnName = column.getName();
AlterTableAddConstraint pk = new AlterTableAddConstraint(session, schema, false);
pk.setPrimaryKeyHash(hash);
pk.setType(AlterTableAddConstraint.PRIMARY_KEY);
pk.setType(CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY);
pk.setTableName(tableName);
pk.setIndexColumns(cols);
command.addConstraintCommand(pk);
......@@ -4952,7 +4947,7 @@ public class Parser {
} else if (readIf("UNIQUE")) {
AlterTableAddConstraint unique = new AlterTableAddConstraint(session, schema, false);
unique.setConstraintName(constraintName);
unique.setType(AlterTableAddConstraint.UNIQUE);
unique.setType(CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_UNIQUE);
IndexColumn[] cols = { new IndexColumn() };
cols[0].columnName = columnName;
unique.setIndexColumns(cols);
......@@ -4972,7 +4967,7 @@ public class Parser {
if (readIf("REFERENCES")) {
AlterTableAddConstraint ref = new AlterTableAddConstraint(session, schema, false);
ref.setConstraintName(constraintName);
ref.setType(AlterTableAddConstraint.REFERENTIAL);
ref.setType(CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_REFERENTIAL);
IndexColumn[] cols = { new IndexColumn() };
cols[0].columnName = columnName;
ref.setIndexColumns(cols);
......
......@@ -80,6 +80,14 @@ public abstract class Prepared {
* @return the result set
*/
public abstract ResultInterface queryMeta();
/**
* Get the command type as defined in CommandInterface
*
* @return the statement type
*/
public abstract int getType();
/**
* Check if this command is read only.
......
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Right;
......@@ -47,4 +48,8 @@ public class AlterIndexRename extends DefineCommand {
return 0;
}
public int getType() {
return CommandInterface.ALTER_INDEX_RENAME;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -51,4 +52,8 @@ public class AlterSchemaRename extends DefineCommand {
return 0;
}
public int getType() {
return CommandInterface.ALTER_SCHEMA_RENAME;
}
}
......@@ -8,6 +8,7 @@ package org.h2.command.ddl;
import java.util.ArrayList;
import java.util.HashSet;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.constraint.Constraint;
import org.h2.constraint.ConstraintCheck;
......@@ -34,26 +35,6 @@ import org.h2.util.New;
*/
public class AlterTableAddConstraint extends SchemaCommand {
/**
* The type of a ALTER TABLE ADD CHECK statement.
*/
public static final int CHECK = 0;
/**
* The type of a ALTER TABLE ADD UNIQUE statement.
*/
public static final int UNIQUE = 1;
/**
* The type of a ALTER TABLE ADD FOREIGN KEY statement.
*/
public static final int REFERENTIAL = 2;
/**
* The type of a ALTER TABLE ADD PRIMARY KEY statement.
*/
public static final int PRIMARY_KEY = 3;
private int type;
private String constraintName;
private String tableName;
......@@ -111,7 +92,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
table.lock(session, true, true);
Constraint constraint;
switch (type) {
case PRIMARY_KEY: {
case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY: {
IndexColumn.mapColumns(indexColumns, table);
index = table.findPrimaryKey();
ArrayList<Constraint> constraints = table.getConstraints();
......@@ -153,7 +134,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
constraint = pk;
break;
}
case UNIQUE: {
case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_UNIQUE: {
IndexColumn.mapColumns(indexColumns, table);
boolean isOwner = false;
if (index != null && canUseUniqueIndex(index, table, indexColumns)) {
......@@ -174,7 +155,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
constraint = unique;
break;
}
case CHECK: {
case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_CHECK: {
int id = getObjectId();
String name = generateConstraintName(table);
ConstraintCheck check = new ConstraintCheck(getSchema(), id, name, table);
......@@ -189,7 +170,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
}
break;
}
case REFERENTIAL: {
case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_REFERENTIAL: {
Table refTable = refSchema.getTableOrView(session, refTableName);
session.getUser().checkRight(refTable, Right.ALL);
if (!refTable.canReference()) {
......
......@@ -8,6 +8,7 @@ package org.h2.command.ddl;
import java.util.ArrayList;
import java.util.List;
import org.h2.command.CommandInterface;
import org.h2.command.Parser;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
......@@ -44,42 +45,6 @@ import org.h2.util.New;
*/
public class AlterTableAlterColumn extends SchemaCommand {
/**
* The type of a ALTER TABLE ALTER COLUMN SET NOT NULL statement.
*/
public static final int NOT_NULL = 0;
/**
* The type of a ALTER TABLE ALTER COLUMN SET NULL statement.
*/
public static final int NULL = 1;
/**
* The type of a ALTER TABLE ALTER COLUMN SET DEFAULT statement.
*/
public static final int DEFAULT = 2;
/**
* The type of a ALTER TABLE ALTER COLUMN statement that changes the column
* data type.
*/
public static final int CHANGE_TYPE = 3;
/**
* The type of a ALTER TABLE ADD statement.
*/
public static final int ADD = 4;
/**
* The type of a ALTER TABLE DROP COLUMN statement.
*/
public static final int DROP = 5;
/**
* The type of a ALTER TABLE ALTER COLUMN SELECTIVITY statement.
*/
public static final int SELECTIVITY = 6;
private Table table;
private Column oldColumn;
private Column newColumn;
......@@ -112,7 +77,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
table.lock(session, true, true);
Sequence sequence = oldColumn == null ? null : oldColumn.getSequence();
switch (type) {
case NOT_NULL: {
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_NOT_NULL: {
if (!oldColumn.isNullable()) {
// no change
break;
......@@ -122,7 +87,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
db.update(session, table);
break;
}
case NULL: {
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_NULL: {
if (oldColumn.isNullable()) {
// no change
break;
......@@ -132,14 +97,14 @@ public class AlterTableAlterColumn extends SchemaCommand {
db.update(session, table);
break;
}
case DEFAULT: {
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_DEFAULT: {
oldColumn.setSequence(null);
oldColumn.setDefaultExpression(session, defaultExpression);
removeSequence(sequence);
db.update(session, table);
break;
}
case CHANGE_TYPE: {
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE: {
oldColumn.setSequence(null);
oldColumn.setDefaultExpression(session, null);
oldColumn.setConvertNullToDefault(false);
......@@ -152,12 +117,12 @@ public class AlterTableAlterColumn extends SchemaCommand {
copyData();
break;
}
case ADD: {
case CommandInterface.ALTER_TABLE_ADD_COLUMN: {
convertAutoIncrementColumn(newColumn);
copyData();
break;
}
case DROP: {
case CommandInterface.ALTER_TABLE_DROP_COLUMN: {
if (table.getColumns().length == 1) {
throw DbException.get(ErrorCode.CANNOT_DROP_LAST_COLUMN, oldColumn.getSQL());
}
......@@ -166,7 +131,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
copyData();
break;
}
case SELECTIVITY: {
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_SELECTIVITY: {
int value = newSelectivity.optimize(session).getValue(session).getInt();
oldColumn.setSelectivity(value);
db.update(session, table);
......@@ -249,10 +214,10 @@ public class AlterTableAlterColumn extends SchemaCommand {
for (Column col : columns) {
newColumns.add(col.getClone());
}
if (type == DROP) {
if (type == CommandInterface.ALTER_TABLE_DROP_COLUMN) {
int position = oldColumn.getColumnId();
newColumns.remove(position);
} else if (type == ADD) {
} else if (type == CommandInterface.ALTER_TABLE_ADD_COLUMN) {
int position;
if (addBefore == null) {
position = columns.length;
......@@ -260,7 +225,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
position = table.getColumn(addBefore).getColumnId();
}
newColumns.add(position, newColumn);
} else if (type == CHANGE_TYPE) {
} else if (type == CommandInterface.ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE) {
int position = oldColumn.getColumnId();
newColumns.remove(position);
newColumns.add(position, newColumn);
......@@ -290,7 +255,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
if (columnList.length() > 0) {
columnList.append(", ");
}
if (type == ADD && nc == newColumn) {
if (type == CommandInterface.ALTER_TABLE_ADD_COLUMN && nc == newColumn) {
Expression def = nc.getDefaultExpression();
columnList.append(def == null ? "NULL" : def.getSQL());
} else {
......@@ -489,4 +454,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
this.newColumn = newColumn;
}
public int getType() {
return type;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.constraint.Constraint;
import org.h2.engine.Right;
......@@ -46,4 +47,8 @@ public class AlterTableDropConstraint extends SchemaCommand {
return 0;
}
public int getType() {
return CommandInterface.ALTER_TABLE_DROP_CONSTRAINT;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Right;
......@@ -49,4 +50,8 @@ public class AlterTableRename extends SchemaCommand {
return 0;
}
public int getType() {
return CommandInterface.ALTER_TABLE_RENAME;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.engine.Database;
import org.h2.engine.DbObject;
import org.h2.engine.Right;
......@@ -55,4 +56,8 @@ public class AlterTableRenameColumn extends DefineCommand {
return 0;
}
public int getType() {
return CommandInterface.ALTER_TABLE_ALTER_COLUMN_RENAME;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -23,21 +24,6 @@ import org.h2.util.StringUtils;
*/
public class AlterUser extends DefineCommand {
/**
* The command type to set the password.
*/
public static final int SET_PASSWORD = 0;
/**
* The command type to rename the user.
*/
public static final int RENAME = 1;
/**
* The command type to change the admin flag.
*/
public static final int ADMIN = 2;
private int type;
private User user;
private String newName;
......@@ -90,7 +76,7 @@ public class AlterUser extends DefineCommand {
session.commit(true);
Database db = session.getDatabase();
switch (type) {
case SET_PASSWORD:
case CommandInterface.ALTER_USER_SET_PASSWORD:
if (user != session.getUser()) {
session.getUser().checkAdmin();
}
......@@ -104,14 +90,14 @@ public class AlterUser extends DefineCommand {
user.setUserPasswordHash(userPasswordHash);
}
break;
case RENAME:
case CommandInterface.ALTER_USER_RENAME:
session.getUser().checkAdmin();
if (db.findUser(newName) != null || newName.equals(user.getName())) {
throw DbException.get(ErrorCode.USER_ALREADY_EXISTS_1, newName);
}
db.renameDatabaseObject(session, user, newName);
break;
case ADMIN:
case CommandInterface.ALTER_USER_ADMIN:
session.getUser().checkAdmin();
if (!admin) {
user.checkOwnsNoSchemas();
......@@ -125,4 +111,8 @@ public class AlterUser extends DefineCommand {
return 0;
}
public int getType() {
return type;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.table.TableView;
......@@ -33,4 +34,8 @@ public class AlterView extends DefineCommand {
return 0;
}
public int getType() {
return CommandInterface.ALTER_VIEW;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.constant.SysProperties;
import org.h2.engine.Database;
......@@ -109,4 +110,8 @@ public class Analyze extends DefineCommand {
this.sampleRows = top;
}
public int getType() {
return CommandInterface.ANALYZE;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -65,4 +66,8 @@ public class CreateAggregate extends DefineCommand {
this.force = force;
}
public int getType() {
return CommandInterface.CREATE_AGGREGATE;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -60,4 +61,8 @@ public class CreateConstant extends SchemaCommand {
this.expression = expr;
}
public int getType() {
return CommandInterface.CREATE_CONSTANT;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.FunctionAlias;
......@@ -82,4 +83,8 @@ public class CreateFunctionAlias extends SchemaCommand {
this.source = source;
}
public int getType() {
return CommandInterface.CREATE_ALIAS;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.engine.Database;
......@@ -106,4 +107,8 @@ public class CreateIndex extends SchemaCommand {
this.comment = comment;
}
public int getType() {
return CommandInterface.CREATE_INDEX;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -114,4 +115,8 @@ public class CreateLinkedTable extends SchemaCommand {
this.originalSchema = originalSchema;
}
public int getType() {
return CommandInterface.CREATE_LINKED_TABLE;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Role;
......@@ -52,4 +53,8 @@ public class CreateRole extends DefineCommand {
return 0;
}
public int getType() {
return CommandInterface.CREATE_ROLE;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -57,4 +58,8 @@ public class CreateSchema extends DefineCommand {
this.authorization = userName;
}
public int getType() {
return CommandInterface.CREATE_SCHEMA;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -80,4 +81,8 @@ public class CreateSequence extends SchemaCommand {
this.cacheSize = cacheSize;
}
public int getType() {
return CommandInterface.CREATE_SEQUENCE;
}
}
......@@ -7,6 +7,7 @@
package org.h2.command.ddl;
import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.command.dml.Insert;
import org.h2.command.dml.Query;
import org.h2.constant.ErrorCode;
......@@ -77,7 +78,7 @@ public class CreateTable extends SchemaCommand {
} else {
AlterTableAddConstraint con = (AlterTableAddConstraint) command;
boolean alreadySet;
if (con.getType() == AlterTableAddConstraint.PRIMARY_KEY) {
if (con.getType() == CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY) {
alreadySet = setPrimaryKeyColumns(con.getIndexColumns());
} else {
alreadySet = false;
......@@ -278,4 +279,8 @@ public class CreateTable extends SchemaCommand {
data.isHidden = isHidden;
}
public int getType() {
return CommandInterface.CREATE_TABLE;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -111,4 +112,8 @@ public class CreateTrigger extends SchemaCommand {
this.onRollback = onRollback;
}
public int getType() {
return CommandInterface.CREATE_TRIGGER;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Database;
......@@ -106,4 +107,8 @@ public class CreateUser extends DefineCommand {
this.comment = comment;
}
public int getType() {
return CommandInterface.CREATE_USER;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -69,4 +70,8 @@ public class CreateUserDataType extends DefineCommand {
return 0;
}
public int getType() {
return CommandInterface.CREATE_DOMAIN;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.command.dml.Query;
import org.h2.constant.ErrorCode;
......@@ -195,4 +196,8 @@ public class CreateView extends SchemaCommand {
session.commit(true);
}
}
public int getType() {
return CommandInterface.CREATE_VIEW;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.engine.Session;
/**
......@@ -29,4 +30,8 @@ public class DeallocateProcedure extends DefineCommand {
this.procedureName = name;
}
public int getType() {
return CommandInterface.DEALLOCATE;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -48,4 +49,8 @@ public class DropAggregate extends DefineCommand {
this.ifExists = ifExists;
}
public int getType() {
return CommandInterface.DROP_AGGREGATE;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -49,4 +50,8 @@ public class DropConstant extends SchemaCommand {
return 0;
}
public int getType() {
return CommandInterface.DROP_CONSTANT;
}
}
......@@ -7,6 +7,7 @@
package org.h2.command.ddl;
import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.engine.Database;
import org.h2.engine.DbObject;
import org.h2.engine.Role;
......@@ -114,4 +115,8 @@ public class DropDatabase extends DefineCommand {
this.deleteFiles = b;
}
public int getType() {
return CommandInterface.DROP_ALL_OBJECTS;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.FunctionAlias;
......@@ -49,4 +50,8 @@ public class DropFunctionAlias extends SchemaCommand {
this.ifExists = ifExists;
}
public int getType() {
return CommandInterface.DROP_ALIAS;
}
}
......@@ -7,6 +7,7 @@
package org.h2.command.ddl;
import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.constraint.Constraint;
import org.h2.engine.Database;
......@@ -72,4 +73,8 @@ public class DropIndex extends SchemaCommand {
return 0;
}
public int getType() {
return CommandInterface.DROP_INDEX;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.engine.Database;
......@@ -52,4 +53,8 @@ public class DropRole extends DefineCommand {
this.ifExists = ifExists;
}
public int getType() {
return CommandInterface.DROP_ROLE;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -51,4 +52,8 @@ public class DropSchema extends DefineCommand {
this.ifExists = ifExists;
}
public int getType() {
return CommandInterface.DROP_SCHEMA;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -52,4 +53,8 @@ public class DropSequence extends SchemaCommand {
return 0;
}
public int getType() {
return CommandInterface.DROP_SEQUENCE;
}
}
......@@ -7,6 +7,7 @@
package org.h2.command.ddl;
import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.constraint.ConstraintReferential;
......@@ -120,4 +121,8 @@ public class DropTable extends SchemaCommand {
}
}
public int getType() {
return CommandInterface.DROP_TABLE;
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Right;
......@@ -52,4 +53,8 @@ public class DropTrigger extends SchemaCommand {
return 0;
}
public int getType() {
return CommandInterface.DROP_TRIGGER;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -64,4 +65,8 @@ public class DropUser extends DefineCommand {
return false;
}
public int getType() {
return CommandInterface.DROP_USER;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -48,4 +49,8 @@ public class DropUserDataType extends DefineCommand {
this.typeName = name;
}
public int getType() {
return CommandInterface.DROP_DOMAIN;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.constraint.ConstraintReferential;
......@@ -70,4 +71,8 @@ public class DropView extends SchemaCommand {
return 0;
}
public int getType() {
return CommandInterface.DROP_VIEW;
}
}
......@@ -7,6 +7,7 @@
package org.h2.command.ddl;
import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Right;
......@@ -26,16 +27,6 @@ import org.h2.util.New;
*/
public class GrantRevoke extends DefineCommand {
/**
* The operation type to grant a right.
*/
public static final int GRANT = 0;
/**
* The operation type to revoke a right.
*/
public static final int REVOKE = 1;
private ArrayList<String> roleNames;
private int operationType;
private int rightMask;
......@@ -92,18 +83,18 @@ public class GrantRevoke extends DefineCommand {
if (grantedRole == null) {
throw DbException.get(ErrorCode.ROLE_NOT_FOUND_1, name);
}
if (operationType == GRANT) {
if (operationType == CommandInterface.GRANT) {
grantRole(grantedRole);
} else if (operationType == REVOKE) {
} else if (operationType == CommandInterface.REVOKE) {
revokeRole(grantedRole);
} else {
DbException.throwInternalError("type=" + operationType);
}
}
} else {
if (operationType == GRANT) {
if (operationType == CommandInterface.GRANT) {
grantRight();
} else if (operationType == REVOKE) {
} else if (operationType == CommandInterface.REVOKE) {
revokeRight();
} else {
DbException.throwInternalError("type=" + operationType);
......@@ -185,4 +176,8 @@ public class GrantRevoke extends DefineCommand {
tables.add(table);
}
public int getType() {
return operationType;
}
}
......@@ -7,6 +7,7 @@
package org.h2.command.ddl;
import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.engine.Procedure;
import org.h2.engine.Session;
......@@ -51,4 +52,8 @@ public class PrepareProcedure extends DefineCommand {
return New.arrayList();
}
public int getType() {
return CommandInterface.PREPARE;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Comment;
import org.h2.engine.Database;
......@@ -146,4 +147,8 @@ public class SetComment extends DefineCommand {
this.column = column;
}
public int getType() {
return CommandInterface.COMMENT;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.engine.Right;
import org.h2.engine.Session;
......@@ -39,4 +40,8 @@ public class TruncateTable extends DefineCommand {
return 0;
}
public int getType() {
return CommandInterface.TRUNCATE_TABLE;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.dml;
import org.h2.command.CommandInterface;
import org.h2.command.ddl.SchemaCommand;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
......@@ -84,4 +85,8 @@ public class AlterSequence extends SchemaCommand {
return 0;
}
public int getType() {
return CommandInterface.ALTER_SEQUENCE;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.dml;
import org.h2.command.CommandInterface;
import org.h2.command.ddl.SchemaCommand;
import org.h2.engine.Right;
import org.h2.engine.Session;
......@@ -19,23 +20,16 @@ import org.h2.table.Table;
*/
public class AlterTableSet extends SchemaCommand {
/**
* Enable the referential integrity.
*/
public static final int REFERENTIAL_INTEGRITY_TRUE = 0;
/**
* Disable the referential integrity.
*/
public static final int REFERENTIAL_INTEGRITY_FALSE = 1;
private String tableName;
private final int type;
private boolean value;
private boolean checkExisting;
public AlterTableSet(Session session, Schema schema, int type) {
public AlterTableSet(Session session, Schema schema, int type, boolean value) {
super(session, schema);
this.type = type;
this.value = value;
}
public void setCheckExisting(boolean b) {
......@@ -55,11 +49,8 @@ public class AlterTableSet extends SchemaCommand {
session.getUser().checkRight(table, Right.ALL);
table.lock(session, true, true);
switch(type) {
case REFERENTIAL_INTEGRITY_TRUE:
table.setCheckForeignKeyConstraints(session, true, checkExisting);
break;
case REFERENTIAL_INTEGRITY_FALSE:
table.setCheckForeignKeyConstraints(session, false, false);
case CommandInterface.ALTER_TABLE_SET_REFERENTIAL_INTEGRITY:
table.setCheckForeignKeyConstraints(session, value, value ? checkExisting : false);
break;
default:
DbException.throwInternalError("type="+type);
......@@ -67,4 +58,8 @@ public class AlterTableSet extends SchemaCommand {
return 0;
}
public int getType() {
return type;
}
}
......@@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.h2.api.DatabaseEventListener;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
......@@ -138,4 +139,8 @@ public class BackupCommand extends Prepared {
return null;
}
public int getType() {
return CommandInterface.BACKUP;
}
}
......@@ -7,6 +7,7 @@
package org.h2.command.dml;
import java.sql.ResultSet;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.engine.Session;
import org.h2.expression.Expression;
......@@ -104,4 +105,8 @@ public class Call extends Prepared {
}
public int getType() {
return CommandInterface.CALL;
}
}
......@@ -7,6 +7,7 @@
package org.h2.command.dml;
import org.h2.api.Trigger;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.engine.Right;
import org.h2.engine.Session;
......@@ -114,4 +115,8 @@ public class Delete extends Prepared {
return null;
}
public int getType() {
return CommandInterface.DELETE;
}
}
......@@ -7,6 +7,7 @@
package org.h2.command.dml;
import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.engine.Procedure;
import org.h2.engine.Session;
......@@ -78,4 +79,8 @@ public class ExecuteProcedure extends Prepared {
return prepared.queryMeta();
}
public int getType() {
return CommandInterface.EXECUTE;
}
}
......@@ -9,6 +9,7 @@ package org.h2.command.dml;
import java.util.Map;
import java.util.TreeMap;
import java.util.Map.Entry;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -113,4 +114,8 @@ public class Explain extends Prepared {
public boolean isReadOnly() {
return true;
}
public int getType() {
return CommandInterface.EXPLAIN;
}
}
......@@ -9,6 +9,7 @@ package org.h2.command.dml;
import java.util.ArrayList;
import org.h2.api.Trigger;
import org.h2.command.Command;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
......@@ -235,4 +236,8 @@ public class Insert extends Prepared {
this.sortedInsertMode = sortedInsertMode;
}
public int getType() {
return CommandInterface.INSERT;
}
}
......@@ -9,6 +9,7 @@ package org.h2.command.dml;
import java.util.ArrayList;
import org.h2.api.Trigger;
import org.h2.command.Command;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
import org.h2.engine.Right;
......@@ -274,4 +275,8 @@ public class Merge extends Prepared {
return null;
}
public int getType() {
return CommandInterface.MERGE;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.dml;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.engine.Session;
import org.h2.result.ResultInterface;
......@@ -43,4 +44,8 @@ public class NoOperation extends Prepared {
return null;
}
public int getType() {
return CommandInterface.NO_OPERATION;
}
}
......@@ -9,6 +9,7 @@ package org.h2.command.dml;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.constant.SysProperties;
import org.h2.engine.Session;
......@@ -79,4 +80,8 @@ public class RunScriptCommand extends ScriptBase {
return null;
}
public int getType() {
return CommandInterface.RUNSCRIPT;
}
}
......@@ -17,6 +17,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import org.h2.command.CommandInterface;
import org.h2.command.Parser;
import org.h2.constant.SysProperties;
import org.h2.constraint.Constraint;
......@@ -582,4 +583,8 @@ public class ScriptCommand extends ScriptBase {
this.charset = charset;
}
public int getType() {
return CommandInterface.SCRIPT;
}
}
......@@ -11,6 +11,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import org.h2.api.Trigger;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
......@@ -1172,4 +1173,8 @@ public class Select extends Query {
return !isForUpdate;
}
public int getType() {
return CommandInterface.SELECT;
}
}
......@@ -8,6 +8,7 @@ package org.h2.command.dml;
import java.util.ArrayList;
import java.util.HashSet;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Session;
......@@ -372,4 +373,8 @@ public class SelectUnion extends Query {
right.fireBeforeSelectTriggers();
}
public int getType() {
return CommandInterface.SELECT;
}
}
......@@ -7,6 +7,7 @@
package org.h2.command.dml;
import java.text.Collator;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.compress.Compressor;
import org.h2.constant.ErrorCode;
......@@ -416,4 +417,8 @@ public class Set extends Prepared {
this.stringValueList = list;
}
public int getType() {
return CommandInterface.SET;
}
}
......@@ -6,6 +6,7 @@
*/
package org.h2.command.dml;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.engine.Database;
import org.h2.engine.Session;
......@@ -17,86 +18,6 @@ import org.h2.result.ResultInterface;
*/
public class TransactionCommand extends Prepared {
/**
* The type of a SET AUTOCOMMIT TRUE statement.
*/
public static final int AUTOCOMMIT_TRUE = 1;
/**
* The type of a SET AUTOCOMMIT FALSE statement.
*/
public static final int AUTOCOMMIT_FALSE = 2;
/**
* The type of a COMMIT statement.
*/
public static final int COMMIT = 3;
/**
* The type of a ROLLBACK statement.
*/
public static final int ROLLBACK = 4;
/**
* The type of a CHECKPOINT statement.
*/
public static final int CHECKPOINT = 5;
/**
* The type of a SAVEPOINT statement.
*/
public static final int SAVEPOINT = 6;
/**
* The type of a ROLLBACK TO SAVEPOINT statement.
*/
public static final int ROLLBACK_TO_SAVEPOINT = 7;
/**
* The type of a CHECKPOINT SYNC statement.
*/
public static final int CHECKPOINT_SYNC = 8;
/**
* The type of a PREPARE COMMIT statement.
*/
public static final int PREPARE_COMMIT = 9;
/**
* The type of a COMMIT TRANSACTION statement.
*/
public static final int COMMIT_TRANSACTION = 10;
/**
* The type of a ROLLBACK TRANSACTION statement.
*/
public static final int ROLLBACK_TRANSACTION = 11;
/**
* The type of a SHUTDOWN statement.
*/
public static final int SHUTDOWN = 12;
/**
* The type of a SHUTDOWN IMMEDIATELY statement.
*/
public static final int SHUTDOWN_IMMEDIATELY = 13;
/**
* The type of a SHUTDOWN COMPACT statement.
*/
public static final int SHUTDOWN_COMPACT = 14;
/**
* The type of a BEGIN {WORK|TRANSACTION} statement.
*/
public static final int BEGIN = 15;
/**
* The type of a SHUTDOWN DEFRAG statement.
*/
public static final int SHUTDOWN_DEFRAG = 16;
private int type;
private String savepointName;
private String transactionName;
......@@ -112,56 +33,56 @@ public class TransactionCommand extends Prepared {
public int update() {
switch (type) {
case AUTOCOMMIT_TRUE:
case CommandInterface.SET_AUTOCOMMIT_TRUE:
session.setAutoCommit(true);
break;
case AUTOCOMMIT_FALSE:
case CommandInterface.SET_AUTOCOMMIT_FALSE:
session.setAutoCommit(false);
break;
case BEGIN:
case CommandInterface.BEGIN:
session.begin();
break;
case COMMIT:
case CommandInterface.COMMIT:
session.commit(false);
break;
case ROLLBACK:
case CommandInterface.ROLLBACK:
session.rollback();
break;
case CHECKPOINT:
case CommandInterface.CHECKPOINT:
session.getUser().checkAdmin();
session.getDatabase().checkpoint();
break;
case SAVEPOINT:
case CommandInterface.SAVEPOINT:
session.addSavepoint(savepointName);
break;
case ROLLBACK_TO_SAVEPOINT:
case CommandInterface.ROLLBACK_TO_SAVEPOINT:
session.rollbackToSavepoint(savepointName);
break;
case CHECKPOINT_SYNC:
case CommandInterface.CHECKPOINT_SYNC:
session.getUser().checkAdmin();
session.getDatabase().sync();
break;
case PREPARE_COMMIT:
case CommandInterface.PREPARE_COMMIT:
session.prepareCommit(transactionName);
break;
case COMMIT_TRANSACTION:
case CommandInterface.COMMIT_TRANSACTION:
session.getUser().checkAdmin();
session.setPreparedTransaction(transactionName, true);
break;
case ROLLBACK_TRANSACTION:
case CommandInterface.ROLLBACK_TRANSACTION:
session.getUser().checkAdmin();
session.setPreparedTransaction(transactionName, false);
break;
case SHUTDOWN_IMMEDIATELY:
case CommandInterface.SHUTDOWN_IMMEDIATELY:
session.getUser().checkAdmin();
session.getDatabase().shutdownImmediately();
break;
case SHUTDOWN:
case SHUTDOWN_COMPACT:
case SHUTDOWN_DEFRAG: {
case CommandInterface.SHUTDOWN:
case CommandInterface.SHUTDOWN_COMPACT:
case CommandInterface.SHUTDOWN_DEFRAG: {
session.getUser().checkAdmin();
session.commit(false);
if (type == SHUTDOWN_COMPACT || type == SHUTDOWN_DEFRAG) {
if (type == CommandInterface.SHUTDOWN_COMPACT || type == CommandInterface.SHUTDOWN_DEFRAG) {
session.getDatabase().setCompactMode(type);
}
// close the database, but don't update the persistent setting
......@@ -211,4 +132,8 @@ public class TransactionCommand extends Prepared {
return null;
}
public int getType() {
return type;
}
}
......@@ -7,6 +7,7 @@
package org.h2.command.dml;
import org.h2.api.Trigger;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
import org.h2.engine.Right;
......@@ -182,4 +183,8 @@ public class Update extends Prepared {
return null;
}
public int getType() {
return CommandInterface.UPDATE;
}
}
......@@ -37,6 +37,7 @@ public class JdbcStatement extends TraceObject implements Statement {
protected final int resultSetConcurrency;
protected boolean closedByResultSet;
private CommandInterface executingCommand;
private int lastExecutedCommandType;
private ArrayList<String> batchCommands;
private boolean escapeProcessing = true;
......@@ -926,10 +927,23 @@ public class JdbcStatement extends TraceObject implements Statement {
* @param c the command
*/
protected void setExecutingStatement(CommandInterface c) {
conn.setExecutingStatement(c == null ? null : this);
if (c == null) {
conn.setExecutingStatement(null);
} else {
conn.setExecutingStatement(this);
lastExecutedCommandType = c.getCommandType();
}
executingCommand = c;
}
/**
* INTERNAL.
* Get the command type of the last executed command.
*/
public int getLastExecutedCommandType() {
return lastExecutedCommandType;
}
/**
* Returns whether this statement is closed.
*
......
......@@ -28,15 +28,18 @@ import java.sql.Statement;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Properties;
import org.h2.command.CommandInterface;
import org.h2.constant.SysProperties;
import org.h2.engine.ConnectionInfo;
import org.h2.jdbc.JdbcConnection;
import org.h2.jdbc.JdbcPreparedStatement;
import org.h2.jdbc.JdbcStatement;
import org.h2.message.DbException;
import org.h2.util.Utils;
import org.h2.util.IOUtils;
import org.h2.util.JdbcUtils;
import org.h2.util.New;
import org.h2.util.ScriptReader;
import org.h2.util.Utils;
/**
* One server thread is opened for each client.
......@@ -131,7 +134,7 @@ public class PgServerThread implements Runnable {
byte[] data = Utils.newBytes(len);
dataInRaw.readFully(data, 0, len);
dataIn = new DataInputStream(new ByteArrayInputStream(data, 0, len));
switch (x) {
switchBlock: switch (x) {
case 0:
server.trace("Init");
int version = readInt();
......@@ -214,7 +217,7 @@ public class PgServerThread implements Runnable {
p.paramType[i] = type;
}
try {
p.prep = conn.prepareStatement(p.sql);
p.prep = (JdbcPreparedStatement) conn.prepareStatement(p.sql);
prepared.put(p.name, p);
sendParseComplete();
} catch (Exception e) {
......@@ -248,6 +251,7 @@ public class PgServerThread implements Runnable {
setParameter(prep.prep, i, d2, formatCodes);
} catch (Exception e) {
sendErrorResponse(e);
break switchBlock;
}
}
int resultCodeCount = readShort();
......@@ -317,7 +321,7 @@ public class PgServerThread implements Runnable {
}
int maxRows = readShort();
Prepared prepared = p.prep;
PreparedStatement prep = prepared.prep;
JdbcPreparedStatement prep = prepared.prep;
server.trace(prepared.sql);
try {
prep.setMaxRows(maxRows);
......@@ -330,12 +334,12 @@ public class PgServerThread implements Runnable {
while (rs.next()) {
sendDataRow(rs);
}
sendCommandComplete(prepared.sql, 0);
sendCommandComplete(prep, 0);
} catch (Exception e) {
sendErrorResponse(e);
}
} else {
sendCommandComplete(prepared.sql, prep.getUpdateCount());
sendCommandComplete(prep, prep.getUpdateCount());
}
} catch (Exception e) {
sendErrorResponse(e);
......@@ -352,28 +356,34 @@ public class PgServerThread implements Runnable {
String query = readString();
ScriptReader reader = new ScriptReader(new StringReader(query));
while (true) {
Statement stat = null;
JdbcStatement stat = null;
try {
String s = reader.readStatement();
if (s == null) {
break;
}
s = getSQL(s);
stat = conn.createStatement();
stat = (JdbcStatement) conn.createStatement();
boolean result = stat.execute(s);
if (result) {
ResultSet rs = stat.getResultSet();
ResultSetMetaData meta = rs.getMetaData();
sendRowDescription(meta);
while (rs.next()) {
sendDataRow(rs);
try {
sendRowDescription(meta);
while (rs.next()) {
sendDataRow(rs);
}
sendCommandComplete(stat, 0);
} catch (Exception e) {
sendErrorResponse(e);
break;
}
sendCommandComplete(s, 0);
} else {
sendCommandComplete(s, stat.getUpdateCount());
sendCommandComplete(stat, stat.getUpdateCount());
}
} catch (SQLException e) {
sendErrorResponse(e);
break;
} finally {
JdbcUtils.closeSilently(stat);
}
......@@ -406,52 +416,55 @@ public class PgServerThread implements Runnable {
return s;
}
private void sendCommandComplete(String sql, int updateCount) throws IOException {
private void sendCommandComplete(JdbcStatement stat, int updateCount) throws IOException {
startMessage('C');
sql = sql.trim().toUpperCase();
// TODO remove remarks at the beginning
String tag;
if (sql.startsWith("INSERT")) {
tag = "INSERT 0 " + updateCount;
} else if (sql.startsWith("DELETE")) {
tag = "DELETE " + updateCount;
} else if (sql.startsWith("UPDATE")) {
tag = "UPDATE " + updateCount;
} else if (sql.startsWith("SELECT") || sql.startsWith("CALL")) {
tag = "SELECT";
} else if (sql.startsWith("BEGIN")) {
tag = "BEGIN";
} else {
server.trace("Check command tag: " + sql);
tag = "UPDATE " + updateCount;
switch (stat.getLastExecutedCommandType()) {
case CommandInterface.INSERT:
writeStringPart("INSERT 0 ");
writeString(Integer.toString(updateCount));
break;
case CommandInterface.UPDATE:
writeStringPart("UPDATE ");
writeString(Integer.toString(updateCount));
break;
case CommandInterface.DELETE:
writeStringPart("DELETE ");
writeString(Integer.toString(updateCount));
break;
case CommandInterface.SELECT:
case CommandInterface.CALL:
writeString("SELECT");
break;
case CommandInterface.BEGIN:
writeString("BEGIN");
break;
default:
server.trace("check CommandComplete tag for command " + stat);
writeStringPart("UPDATE ");
writeString(Integer.toString(updateCount));
}
writeString(tag);
sendMessage();
}
private void sendDataRow(ResultSet rs) throws IOException {
try {
int columns = rs.getMetaData().getColumnCount();
String[] values = new String[columns];
for (int i = 0; i < columns; i++) {
values[i] = rs.getString(i + 1);
}
startMessage('D');
writeShort(columns);
for (String s : values) {
if (s == null) {
writeInt(-1);
} else {
// TODO write Binary data
byte[] d2 = s.getBytes(getEncoding());
writeInt(d2.length);
write(d2);
}
private void sendDataRow(ResultSet rs) throws Exception {
int columns = rs.getMetaData().getColumnCount();
String[] values = new String[columns];
for (int i = 0; i < columns; i++) {
values[i] = rs.getString(i + 1);
}
startMessage('D');
writeShort(columns);
for (String s : values) {
if (s == null) {
writeInt(-1);
} else {
// TODO write Binary data
byte[] d2 = s.getBytes(getEncoding());
writeInt(d2.length);
write(d2);
}
sendMessage();
} catch (Exception e) {
sendErrorResponse(e);
}
sendMessage();
}
private String getEncoding() {
......@@ -525,51 +538,47 @@ public class PgServerThread implements Runnable {
sendMessage();
}
private void sendRowDescription(ResultSetMetaData meta) throws IOException {
try {
if (meta == null) {
sendNoData();
} else {
int columns = meta.getColumnCount();
int[] types = new int[columns];
int[] precision = new int[columns];
String[] names = new String[columns];
for (int i = 0; i < columns; i++) {
String name = meta.getColumnName(i + 1);
names[i] = name;
int type = meta.getColumnType(i + 1);
type = PgServer.convertType(type);
// the ODBC client needs the column pg_catalog.pg_index
// to be of type 'int2vector'
// if (name.equalsIgnoreCase("indkey") &&
// "pg_index".equalsIgnoreCase(meta.getTableName(i + 1))) {
// type = PgServer.PG_TYPE_INT2VECTOR;
// }
precision[i] = meta.getColumnDisplaySize(i + 1);
server.checkType(type);
types[i] = type;
}
startMessage('T');
writeShort(columns);
for (int i = 0; i < columns; i++) {
writeString(names[i].toLowerCase());
// object ID
writeInt(0);
// attribute number of the column
writeShort(0);
// data type
writeInt(types[i]);
// pg_type.typlen
writeShort(getTypeSize(types[i], precision[i]));
// pg_attribute.atttypmod
writeInt(-1);
// text
writeShort(0);
}
sendMessage();
private void sendRowDescription(ResultSetMetaData meta) throws Exception {
if (meta == null) {
sendNoData();
} else {
int columns = meta.getColumnCount();
int[] types = new int[columns];
int[] precision = new int[columns];
String[] names = new String[columns];
for (int i = 0; i < columns; i++) {
String name = meta.getColumnName(i + 1);
names[i] = name;
int type = meta.getColumnType(i + 1);
type = PgServer.convertType(type);
// the ODBC client needs the column pg_catalog.pg_index
// to be of type 'int2vector'
// if (name.equalsIgnoreCase("indkey") &&
// "pg_index".equalsIgnoreCase(meta.getTableName(i + 1))) {
// type = PgServer.PG_TYPE_INT2VECTOR;
// }
precision[i] = meta.getColumnDisplaySize(i + 1);
server.checkType(type);
types[i] = type;
}
} catch (Exception e) {
sendErrorResponse(e);
startMessage('T');
writeShort(columns);
for (int i = 0; i < columns; i++) {
writeString(names[i].toLowerCase());
// object ID
writeInt(0);
// attribute number of the column
writeShort(0);
// data type
writeInt(types[i]);
// pg_type.typlen
writeShort(getTypeSize(types[i], precision[i]));
// pg_attribute.atttypmod
writeInt(-1);
// text
writeShort(0);
}
sendMessage();
}
}
......@@ -739,10 +748,14 @@ public class PgServerThread implements Runnable {
}
private void writeString(String s) throws IOException {
write(s.getBytes(getEncoding()));
writeStringPart(s);
write(0);
}
private void writeStringPart(String s) throws IOException {
write(s.getBytes(getEncoding()));
}
private void writeInt(int i) throws IOException {
dataOut.writeInt(i);
}
......@@ -813,7 +826,7 @@ public class PgServerThread implements Runnable {
/**
* The prepared statement.
*/
PreparedStatement prep;
JdbcPreparedStatement prep;
/**
* The list of parameter types (if set).
......
......@@ -13,8 +13,8 @@ import java.util.BitSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.zip.CRC32;
import org.h2.command.CommandInterface;
import org.h2.command.ddl.CreateTableData;
import org.h2.command.dml.TransactionCommand;
import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
......@@ -465,8 +465,8 @@ public class PageStore implements CacheWriter {
recoveryRunning = false;
}
long start = System.currentTimeMillis();
boolean isCompactFully = compactMode == TransactionCommand.SHUTDOWN_COMPACT;
boolean isDefrag = compactMode == TransactionCommand.SHUTDOWN_DEFRAG;
boolean isCompactFully = compactMode == CommandInterface.SHUTDOWN_COMPACT;
boolean isDefrag = compactMode == CommandInterface.SHUTDOWN_DEFRAG;
int test;
// isCompactFully = isDefrag = true;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论