private static void TryExecute(string s, SQLiteServerConnection connection) { try { using (var command = new SQLiteServerCommand(s, connection)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { for (var i = 0; i < reader.FieldCount; ++i) { Console.Write($"\t{reader[i]}"); } Console.WriteLine(""); } var r = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("The command(s) completed successfully"); Console.ForegroundColor = r; } } } catch (SQLiteServerException e) { var r = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(e.Message); Console.ForegroundColor = r; } }
protected SQLiteServerConnection CreateConnection( IConnectionBuilder connectionBuilder, SQLiteServerConnection parent) { var connection = new SQLiteServerConnection(parent.ConnectionString, connectionBuilder); _connections.Add(connection); return(connection); }
public void DestinationIsNull() { var source = CreateConnection(); source.Open(); const SQLiteServerConnection destination = null; Assert.Throws <ArgumentNullException>(() => source.BackupDatabase(destination, "main", "main", -1, null, 0)); source.Close(); }
private void OpenDb() { _connectionServer = new SQLiteServerConnection($"Data Source={_source};Version=3;", Address, Port, Backlog, HeartBeatTimeOut); _connectionServer.Open(); if (!_useClient) { return; } _connectionClient = new SQLiteServerConnection($"Data Source={_source};Version=3;", Address, Port, Backlog, HeartBeatTimeOut); _connectionClient.Open(); }
public void BadDatabaseNameBecomesBroken() { var server = new SQLiteServerConnection("Data Source=;Version=3;", Address, Port, Backlog, HeartBeatTimeOut); Assert.Throws <ArgumentException>(() => { server.Open(); }); // make sure it is broken. Assert.AreEqual(ConnectionState.Broken, server.State); // it is broken, so it will not work. Assert.Throws <InvalidOperationException>(() => { server.Open(); }); }
/// <inheritdoc /> public async Task <bool> ConnectAsync(SQLiteServerConnection connection) { // sanity check ThrowIfDisposed(); // save the connection _connection = connection; // sanity check if (_connectionController?.Connected ?? false) { throw new SQLiteServerException("Already connected!"); } _connectionController = new ConnectionsController(_address, _port, _backlog, _heartBeatTimeOutInMs); if (!_connectionController.Connect()) { throw new SQLiteServerException("Unable to connected."); } // wait untl we are connected await Task.Run(async() => { var watch = System.Diagnostics.Stopwatch.StartNew(); while (!_connectionController.Connected) { // yield all the work. await Task.Yield(); // check for delay if (_heartBeatTimeOutInMs > 0 && watch.ElapsedMilliseconds >= _heartBeatTimeOutInMs) { // we timed out. break; } } watch.Stop(); }).ConfigureAwait(false); if (!_connectionController.Connected) { throw new SQLiteServerException("Timmed out waiting for update."); } return(true); }
protected SQLiteServerConnection CreateConnection(IConnectionBuilder connectionBuilder = null , int?defaultTimeout = null, string source = null) { if (connectionBuilder == null) { connectionBuilder = new SocketConnectionBuilder(Address, Port, Backlog, HeartBeatTimeOut); } var connectionString = $"Data Source={source ?? _sources.First()}"; if (defaultTimeout != null) { connectionString = $"{connectionString};Default Timeout={(int)defaultTimeout}"; } var connection = new SQLiteServerConnection(connectionString, connectionBuilder); _connections.Add(connection); return(connection); }
private static void Main(string[] args) { var path = Directory.GetCurrentDirectory(); var source = Path.Combine(path, "sample.db"); Console.WriteLine($"Db: {source}"); var connection = new SQLiteServerConnection($"Data Source={source};Version=3;", Address, Port, Backlog, HeartBeatTimeOut); try { connection.Open(); Console.CursorVisible = true; Console.WriteLine("Press Exit to ... exit (duh)"); while (true) { var s = Console.ReadLine(); if (s == null) { continue; } if (s.ToLower() == "exit") { Console.WriteLine("Ok, bye"); break; } TryExecute(s, connection); } connection.Close(); } catch (Exception e) { Console.WriteLine($"Unable to open '{source}', please check your permissions."); Console.WriteLine($"Error was : {e.Message}."); } }