Ejemplo n.º 1
0
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		static void Main()
		{
			SQLiteClient db;
			SQLiteResultSet results;

			Console.WriteLine("Basic test app for SQLite.NET. Enter a single line sql query and it will be run against the database.\r\n");

			Console.WriteLine("Opening database 'test.db'...\r\n");
			
			try {
				// Open database
				db = new SQLiteClient("test.db");

			} catch (SQLiteException e) {
				Console.WriteLine("Fatal error: {0}", e.Message);
				Console.ReadLine();
				return;
			}

			Console.WriteLine("Available tables:");

			ArrayList tables = db.GetColumn("SELECT name FROM sqlite_master WHERE type = 'table'");

			foreach (string tableName in tables) {
				Console.WriteLine("\t" + tableName);
			}

			// Main loop
			while (true) {
				Console.Write("SQL> ");
				string input = Console.ReadLine();

				if (input == null || input.Trim() == "") {
					continue;
				}

				if (input == ".quit") {
					return;
				}

				try {
					results = db.Execute(input);

					ConsoleTable table = new ConsoleTable();
					table.SetHeaders(results.ColumnNames);

					// Loop through the results and display them
					foreach (ArrayList arr in results.Rows) {
						table.AppendRow(arr);
					}

					while (results.IsMoreData) {
						Hashtable foo = results.GetRowHash();
						foo.GetType();
					}

					Console.WriteLine(table.ToString());

				} catch (SQLiteException e) {
					Console.WriteLine(e.Message);
				}
			}
		}
Ejemplo n.º 2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            SQLiteClient    db;
            SQLiteResultSet results;

            Console.WriteLine("Basic test app for SQLite.NET. Enter a single line sql query and it will be run against the database.\r\n");

            Console.WriteLine("Opening database 'test.db'...\r\n");

            try {
                // Open database
                db = new SQLiteClient("test.db");
            } catch (SQLiteException e) {
                Console.WriteLine("Fatal error: {0}", e.Message);
                Console.ReadLine();
                return;
            }

            Console.WriteLine("Available tables:");

            ArrayList tables = db.GetColumn("SELECT name FROM sqlite_master WHERE type = 'table'");

            foreach (string tableName in tables)
            {
                Console.WriteLine("\t" + tableName);
            }

            // Main loop
            while (true)
            {
                Console.Write("SQL> ");
                string input = Console.ReadLine();

                if (input == null || input.Trim() == "")
                {
                    continue;
                }

                if (input == ".quit")
                {
                    return;
                }

                try {
                    results = db.Execute(input);

                    ConsoleTable table = new ConsoleTable();
                    table.SetHeaders(results.ColumnNames);

                    // Loop through the results and display them
                    foreach (ArrayList arr in results.Rows)
                    {
                        table.AppendRow(arr);
                    }

                    while (results.IsMoreData)
                    {
                        Hashtable foo = results.GetRowHash();
                        foo.GetType();
                    }

                    Console.WriteLine(table.ToString());
                } catch (SQLiteException e) {
                    Console.WriteLine(e.Message);
                }
            }
        }