/// <summary> /// Insert retrived data into destination table /// </summary> /// <param name="server">ip or name of the destination database</param> /// <param name="keyspace">name of the keyspace to use for the insert</param> /// <param name="columnFamily">name of the column family for the insert</param> /// <param name="sourceData">data retrieved from the source</param> private static void InsertIntoDest(string server, string keyspace, string columnFamily, List <dynamic> sourceData, TransferResultsInfo info) { try { CqlConnection destConn = new CqlConnection("Contact Points=" + server, server); CqlCommand destCmd = new CqlCommand(); destConn.Open(); destConn.ChangeDatabase(keyspace); destCmd.Connection = destConn; destCmd.CommandText = "SELECT COUNT(*) FROM " + columnFamily; info.OriginalDestCount = Convert.ToInt32(destCmd.ExecuteScalar()); destCmd.InsertDynamicList(sourceData, columnFamily); destCmd.CommandText = "SELECT COUNT(*) FROM " + columnFamily; info.AfterDestCount = Convert.ToInt32(destCmd.ExecuteScalar()); //cleanup destCmd.Connection.Close(); destCmd.Connection.Dispose(); destCmd.Dispose(); } catch (Exception ex) { info.Message = "Error writting to destination: \r\n" + ex.Message; } }
// ReSharper disable InconsistentNaming public void Issue19_PrepareAndSelectCountStar() // ReSharper restore InconsistentNaming { //Assume const string insertCql = @"select count(*) from system.schema_keyspaces;"; long count; //Act using(var connection = new CqlConnection(ConnectionString)) { connection.Open(); //known issue in Cassandra 2.0.0 and 2.0.1. Prepare returns wrong results for count(*) queries Assert.IsNotNull(connection.ServerVersion); if(connection.ServerVersion.Equals("2.0.0") || connection.ServerVersion.Equals("2.0.1")) return; //insert data var cmd = new CqlCommand(connection, insertCql, CqlConsistency.Quorum); cmd.Prepare(); count = (long)(cmd.ExecuteScalar()); } Assert.IsTrue(count > 0, "Count should be larger than zero"); }