protected override SqlExpression GetInsertIdentityExpression(MetaDataMember member) { var exp = new SqlVariable(member.Type, typeProvider.From(member.Type), "NEXT VALUE FOR " + FirebirdSqlBuilder.GetSequenceName(member), dominatingExpression); return(exp); }
protected override SqlExpression GetReturnIdentityExpression(MetaDataMember idMember, bool isOutputFromInsert) { var name = string.Format("GEN_ID({0},0)", FirebirdSqlBuilder.GetSequenceName(idMember)); return(new SqlVariable(typeof(int), typeProvider.From(typeof(int)), name, dominatingExpression)); //var selection = new SqlVariable(typeof(int), typeProvider.From(typeof(int)), name, dominatingExpression); //var from = new SqlVariable(typeof(int), typeProvider.From(typeof(int)), "$$FFF", dominatingExpression); //return new SqlSelect(selection, new SqlSource(SqlNodeType.Variable, from), dominatingExpression); }
private string GetDropSquenceCommand(MetaTable metaTable) { if (metaTable.RowType.DBGeneratedIdentityMember == null) { return(null); } var commandText = "DROP SEQUENCE " + FirebirdSqlBuilder.GetSequenceName(metaTable.RowType.DBGeneratedIdentityMember); return(commandText); }
void IProviderExtend.CreateForeignKeys(MetaTable metaTable) { //var metaTable = services.Model.GetTable(metaTable); var sqlBuilder = new FirebirdSqlBuilder(this); var commands = sqlBuilder.GetCreateForeignKeyCommands(metaTable); foreach (var command in commands) { services.Context.ExecuteCommand(command); } }
void IProviderExtend.DeleteTable(MetaTable metaTable) { //var metaTable = services.Model.GetTable(metaTable); //var sql = "DROP TABLE {0}"; //sql = string.Format(sql, metaTable.TableName); //services.Context.ExecuteCommand(sql); var commands = new FirebirdSqlBuilder(this).GetDropTableCommands(metaTable); foreach (var command in commands) { Debug.Assert(!string.IsNullOrEmpty(command)); services.Context.ExecuteCommand(command); } }
void IProviderExtend.CreateTable(MetaTable metaTable) { //var metaTable = services.Model.GetTable(metaTable); //var sqlBuilder = new FirebirdSqlBuilder(this); //var command = sqlBuilder.GetCreateTableCommand(metaTable); //services.Context.ExecuteCommand(command); var sqlBuilder = new FirebirdSqlBuilder(this); var commands = sqlBuilder.GetCreateTableCommands(metaTable); foreach (var command in commands) { Debug.Assert(command != null); services.Context.ExecuteCommand(command); } }
void IProvider.CreateDatabase() { var connection = ((FbConnection)Connection); var builder = new FbConnectionStringBuilder(connection.ConnectionString); if (File.Exists(builder.Database)) { throw SqlClient.Error.CreateDatabaseFailedBecauseSqlCEDatabaseAlreadyExists(services.Model.DatabaseName); } FbConnection.CreateDatabase(connection.ConnectionString); connection.Open(); var transaction = connection.BeginTransaction(); var sqlBuilder = FirebirdSqlBuilder.CreateInstance(this); try { if (services.Model.GetTables().Count() == 0) { throw SqlClient.Error.CreateDatabaseFailedBecauseOfContextWithNoTables(services.Model.DatabaseName); } var model = services.Model; //foreach (var table in model.GetTables()) //{ // string createTableCommand = sqlBuilder.GetCreateTableCommand(table); // if (!string.IsNullOrEmpty(createTableCommand)) // Execute(connection, transaction, createTableCommand); //} //Create Generator //foreach (var table in model.GetTables()) //{ // if (table.RowType.DBGeneratedIdentityMember != null) // { // var commandText = "CREATE SEQUENCE " + FirebirdSqlBuilder.GetSequenceName(table.RowType.DBGeneratedIdentityMember); // Execute(connection, transaction, commandText); // } //} //foreach (var table in model.GetTables()) //{ // var commandText = sqlBuilder.GetCreatePrimaryKeyCommand(table); // if (!string.IsNullOrEmpty(commandText)) // Execute(connection, transaction, commandText); //} foreach (var table in model.GetTables()) { var commands = sqlBuilder.GetCreateTableCommands(table); foreach (var command in commands) { Execute(connection, transaction, command); } } foreach (MetaTable table in model.GetTables()) { foreach (string commandText in sqlBuilder.GetCreateForeignKeyCommands(table)) { if (!string.IsNullOrEmpty(commandText)) { Execute(connection, transaction, commandText); } } } transaction.Commit(); } catch { transaction.Rollback(); throw; } finally { connection.Close(); } }