Example #1
0
        void IProviderExtend.CreateTable(MetaTable metaTable)
        {
            var sqlBuilder = new SQLiteSqlBuilder(this);
            var commands   = sqlBuilder.GetCreateTableCommands(metaTable);

            foreach (var command in commands)
            {
                services.Context.ExecuteCommand(command);
            }
        }
Example #2
0
        void IProvider.CreateDatabase()
        {
            if (File.Exists(dbName))
            {
                throw SqlClient.Error.CreateDatabaseFailedBecauseSqlCEDatabaseAlreadyExists(dbName);
            }

            //创数据库文件
            SQLiteConnection.CreateFile(dbName);

            //var connection = new SQLiteConnection(GetConnectionString(dbName));
            //services.Context.Connection.Open();
            //var transaction = services.Context.Connection.BeginTransaction();
            //services.Context.Transaction = transaction;
            try
            {
                var       SQLiteSqlBuilder = new SQLiteSqlBuilder(this);
                MetaModel model            = services.Model;
                foreach (MetaTable table in model.GetTables())
                {
                    //string createTableCommand = SQLiteSqlBuilder.GetCreateTableCommand(table);

                    //if (!string.IsNullOrEmpty(createTableCommand))
                    //    Execute(connection, transaction, createTableCommand);
                    var commands = SQLiteSqlBuilder.GetCreateTableCommands(table);
                    foreach (var command in commands)
                    {
                        //Execute(connection, transaction, command);
                        services.Context.ExecuteCommand(command);
                    }
                }

                //-----------------SQLite不支持外键--------------------/

                /*
                 * foreach (MetaTable table in model.GetTables())
                 *  foreach (string commandText in SQLiteSqlBuilder.GetCreateForeignKeyCommands(table))
                 *      if (!string.IsNullOrEmpty(commandText))
                 *          Execute(connection, transaction, commandText);
                 */
                //transaction.Commit();
            }
            catch
            {
                //transaction.Rollback();
                throw;
            }
            finally
            {
                //Connection.Close();
            }
        }