public static void DoNotBeConfusedByRepeatedFieldNames()
        {
            var databaseInitialisation = @"
				CREATE TABLE test(id INTEGER, name TEXT);
				INSERT INTO test VALUES (1, 'Bob');
				INSERT INTO test VALUES (2, 'Jack');
			"            ;

            int?fieldCount = null;

            using (var reusableConnection = CreateReusableConnection(databaseInitialisation))
            {
                var proxy = new SqlProxy(() => reusableConnection, queryRecorder: criteria => { }, scalarQueryRecorder: criteria => { }, nonQueryRowCountRecorder: criteria => { });
                using (var proxyConnection = new RemoteSqlConnectionClient(proxy, proxy.GetNewConnectionId()))
                {
                    using (var command = proxyConnection.CreateCommand("SELECT id, id, name FROM Test"))
                    {
                        proxyConnection.Open();
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                fieldCount = reader.FieldCount;
                                break;
                            }
                        }
                    }
                }
            }

            Assert.NotNull(fieldCount);
            Assert.Equal(3, fieldCount.Value);
        }
Пример #2
0
        public void Execute(ImySqlRequest req, mySqlEndResponseDelegate callbackHandler, Control ctrl)
        {
            this.FormsControl   = ctrl;
            this.CallbackMethod = callbackHandler;
            this.mRequest       = (XmlRpcMySqlRequest)req;
            SqlProxy proxy = XmlRpcProxyGen.Create <SqlProxy>();

            proxy.Url = this.EndpointUri;
            proxy.BeginExecute(this.mRequest.Request, new AsyncCallback(this.ExecuteResponse), null);
        }
Пример #3
0
        public void CanCreateNewBookmark()
        {
            var proxy = SqlProxy.Create <DboSchema>();

            var success = proxy.SaveBookmark("TestBookMark", DateTime.Now) == 5;

            var exists = proxy.GetBookmarks("TestBookMark").Any();

            Assert.IsTrue(success, "Could not create bookmark");
        }
Пример #4
0
        public void CanCreateAndSelectSingleBookMarWithFunc()
        {
            var proxy = SqlProxy.Create <DboSchema>();

            var success = proxy.SaveBookmark("SingleAnotherBookMark", DateTime.Now) == 5;

            var exists = proxy.GetSingleBookmarks("SingleAnotherBookMark") != null;

            Assert.IsTrue(exists, "Could not find any bookmarks");
        }
Пример #5
0
        public void CanCreateAndSelectBookMarkWithProc()
        {
            var proxy = SqlProxy.Create <DboSchema>();

            var success = proxy.SaveBookmark("AnotherBookMarkProc", DateTime.Now) == 5;

            var exists = proxy.GetBookmarksProc("AnotherBookMarkProc").Any();

            Assert.IsTrue(exists, "Could not find any bookmarks");
        }
        public static void ProxyAndReplayQueryForInMemorySqliteDatabaseViaDapper()
        {
            var databaseInitialisation = @"
				CREATE TABLE test(id INTEGER, name TEXT);
				INSERT INTO test VALUES (1, 'Bob');
				INSERT INTO test VALUES (2, 'Jack');
			"            ;

            // Create an in-memory database and perform a query that will populate a cache that will allow replaying those queries without having to
            // hit the database. The read-write "DictionaryCache" requires a way to execute SQL (so that it can take a SQL statement and generate a
            // disconnected DataSet to cache the contents of) but we'll only need the read methods of the cache class - so, before throwing away
            // the DictionaryCache reference after loading the data from the db, get a read-only wrapper so that the SQL Runner that the read-write
            // cache requires can be tidied up.
            List <string>           namesFromSqlCalls;
            ReadOnlyDictionaryCache readOnlyCache;

            using (var reusableConnection = CreateReusableConnection(databaseInitialisation))
            {
                var cache = new DictionaryCache(new SqliteRunner(reusableConnection), infoLogger: Console.WriteLine);
                var proxy = new SqlProxy(() => reusableConnection, cache.QueryRecorder, cache.ScalarQueryRecorder, cache.NonQueryRowCountRecorder);
                using (var proxyConnection = new RemoteSqlConnectionClient(proxy, proxy.GetNewConnectionId()))
                {
                    namesFromSqlCalls = proxyConnection.Query <TestRow>("SELECT * FROM test").Select(row => row.Name).ToList();
                }
                readOnlyCache = new ReadOnlyDictionaryCache(cache);
            }

            // Use the read-only cache to create an alternate IDbConnection instance (a SqlReplayer) that will allow the same SQL statement to be
            // executed and the same data returned, without actually requiring the database
            List <string> namesFromReplayedCalls;
            var           replayer = new SqlReplayer(readOnlyCache.DataRetriever, readOnlyCache.ScalarDataRetriever, readOnlyCache.NonQueryRowCountRetriever);

            using (var replayerConnection = new RemoteSqlConnectionClient(replayer, replayer.GetNewConnectionId()))
            {
                replayerConnection.ConnectionString = _sqliteInMemoryCacheConnectionString;
                using (var command = replayerConnection.CreateCommand("SELECT * FROM test"))
                {
                    namesFromReplayedCalls = replayerConnection.Query <TestRow>("SELECT * FROM test").Select(row => row.Name).ToList();
                }
            }

            var expectedValues = new List <string> {
                "Bob", "Jack"
            };

            Assert.Equal(expectedValues, namesFromSqlCalls);
            Assert.Equal(expectedValues, namesFromReplayedCalls);
        }
Пример #7
0
        public void ExecuteResponse(IAsyncResult asr)
        {
            XmlRpcAsyncResult result         = (XmlRpcAsyncResult)asr;
            SqlProxy          clientProtocol = (SqlProxy)result.ClientProtocol;

            clientProtocol.Url = this.EndpointUri;
            try
            {
                XmlRpcRespStruct_Sql sql = clientProtocol.EndExecute(asr);
                this.mResponse = new XmlRpcMySqlResponse(sql.mResultset);
            }
            catch (Exception exception)
            {
                this.mResponse = new XmlRpcMySqlResponse(exception);
            }
            if (this.FormsControl != null)
            {
                this.FormsControl.Invoke(new mySqlEndResponseDelegate(this.CallbackMethod.Invoke), new object[] { this, this.Response });
            }
        }