Example #1
0
        /// <summary>
        /// Opens the transaction log and runs it.
        /// </summary>
        private void RunScript()
        {
            if (TracingHelper.TraceEnabled)
            {
                TracingHelper.Write();
            }

            if (!(new FileInfo(sFileScript)).Exists)
            {
                return;
            }

            bRestoring = true;

            dDatabase.IsReferentialIntegrity = false;

            ArrayList channel = new ArrayList();

            channel.Add(cSystem);

            Channel current = cSystem;
            int     size    = 1;

            try
            {
                DateTime     time = DateTime.Now;
                StreamReader r    = new StreamReader(sFileScript);

                while (true)
                {
                    string s = r.ReadLine();

                    if (s == null)
                    {
                        break;
                    }

                    if (s.StartsWith("/*C"))
                    {
                        int id = Int32.Parse(s.Substring(3, (s.IndexOf('*', 4) - 3)));

                        if (id > (channel.Count - 1))
                        {
                            current = new Channel(cSystem, id);
                            channel.Add(current);
                            dDatabase.RegisterChannel(current);
                        }
                        else
                        {
                            current = (Channel)channel[id];
                        }

                        s = s.Substring(s.IndexOf('/', 1) + 1);
                    }

                    if (!s.Equals(""))
                    {
                        dDatabase.Execute(s, current);
                    }

                    if (s.Equals("DISCONNECT"))
                    {
                        int id = current.Id;

                        current = new Channel(cSystem, id);

                        channel.RemoveAt(id);
                        channel.Insert(id, current);
                    }
                }

                r.Close();

                for (int i = 0; i < size; i++)
                {
                    current = (Channel)channel[i];

                    if (current != null)
                    {
                        current.Rollback();
                    }
                }

                TimeSpan execution = DateTime.Now.Subtract(time);

                if (TracingHelper.TraceEnabled)
                {
                    TracingHelper.Write((Int64)execution.TotalMilliseconds);
                }
            }
            catch (IOException e)
            {
                throw TracingHelper.Error(TracingHelper.FILE_IO_ERROR, sFileScript + " " + e);
            }

            dDatabase.IsReferentialIntegrity = true;

            bRestoring = false;
        }
Example #2
0
 public void close()
 {
     db.Execute("shutdown", myChannel);
     myChannel.Disconnect();
 }
Example #3
0
        static void Main(string[] args)
        {
            // Create an in memory database by creating with the name "."
            // This has no logging or other disk access
            //Database db = new Database(".");
            Database db = new Database("mydb");
            // The "sa" user is created by default with no password, so we can connect
            // using this user
            Channel myChannel = db.Connect("sa","");
            //All queries return a Result object
            Result rs;
            // We need a string to enter our queries
            string query = "";

            // While the query is not the quit command
            while (!query.ToLower().Equals("quit"))
            {
                // Write a little prompt out to the console
                Console.Write("SQL> ");
                // Read a line of text
                query = Console.ReadLine();
                // Is it our quit command?
                if (!query.ToLower().Equals("quit"))
                {
                    // No, execute it using our Channel object
                    rs = db.Execute(query,myChannel);
                    // If there was an error
                    if (rs.Error != null)
                    {
                        // Print the error message out to the console
                        Console.WriteLine(rs.Error);
                    }
                    else
                    {
                        // Write out some statistics
                        Console.Write(rs.Size + " rows returned, " + rs.UpdateCount + " rows affected.\n\n");
                        // If we had records returned
                        if (rs.Root != null)
                        {
                            // Get the first one
                            Record r = rs.Root;
                            // Get the column count from the Result Object
                            int column_count = rs.ColumnCount;
                            for (int x = 0; x < column_count;x++)
                            {
                                // Print out the column names
                                Console.Write(rs.Label[x]);
                                Console.Write("\t");
                            }
                            Console.Write("\n");
                            while (r != null)
                            {
                                for (int x = 0; x < column_count;x++)
                                {
                                    // Write out the data values
                                    Console.Write(r.Data[x]);
                                    Console.Write("\t");
                                }
                                Console.Write("\n");
                                // Get the next Record object
                                r = r.Next;
                            }
                            Console.Write("\n");
                        }
                    }
                }
                /*else
                {
                    //System.Diagnostics.Debugger.Launch();
                    rs = db.execute("shutdown",myChannel);
                    // If there was an error
                    if (rs.Error != null)
                    {
                        // Print the error message out to the console
                        Console.WriteLine(rs.Error);
                        Console.WriteLine("Press [ENTER] to exit.");
                        Console.ReadLine();
                    }

                }*/
            }
        }