Exemple #1
0
        internal static void ImportSql(Stream sql)
        {
            // Import data (we only have CREATE TABLE and INSERT INTO statements)
            using (StreamReader reader = new StreamReader(sql))
                using (BulkTransaction helper = BulkTransaction.Create())
                {
                    List <string> buffer = new List <string>();
                    while (!reader.EndOfStream)
                    {
                        string cmd = NextStatement(reader, buffer);
                        if (cmd == null || cmd.Length == 0)
                        {
                            continue;
                        }

                        int index = cmd.ToUpper().IndexOf("CREATE TABLE");
                        if (index > -1)
                        {
                            ParseCreate(ref cmd, index);
                        }

                        //Run the command in the transaction.
                        helper.Execute(cmd);
                    }
                    helper.Commit();
                }
        }
Exemple #2
0
        public unsafe void saveChanges()
        {
            if (blockCache.Count == 0)
            {
                return;
            }
            List <BlockPos> tempCache = blockCache;
            string          date      = new String('-', 19); //yyyy-mm-dd hh:mm:ss

            using (BulkTransaction transaction = BulkTransaction.Create())
            {
                fixed(char *ptr = date)
                {
                    ptr[4] = '-'; ptr[7] = '-'; ptr[10] = ' '; ptr[13] = ':'; ptr[16] = ':';
                    DoSaveChanges(tempCache, ptr, date, transaction);
                }
            }
            tempCache.Clear();
            blockCache = new List <BlockPos>();
            Server.s.Log("Saved BlockDB changes for:" + name);
        }