public void InsertData(LabyrinthGenerator generator) { PreparedStatement statement = session.Prepare("INSERT INTO connections (level1, room1, level2, room2) VALUES (?, ?, ?, ?);"); foreach (var room1 in generator.connections.Keys) { foreach (var room2 in generator.connections[room1]) { /* * session.Execute(string.Format( * "INSERT INTO labyrinth.connections (level1, room1, level2, room2) VALUES ({0}, {1}, {2}, {3});", * room1.levelNumber, room1.roomNumber, room2.levelNumber, room2.roomNumber)); */ BoundStatement boundStatement = new BoundStatement(statement); session.Execute(boundStatement.Bind(room1.levelNumber, room1.roomNumber, room2.levelNumber, room2.roomNumber)); } } statement = session.Prepare("INSERT INTO books (level, room, name) VALUES (?, ?, ?);"); foreach (var room in generator.booksInRooms.Keys) { BoundStatement boundStatement = new BoundStatement(statement); session.Execute(boundStatement.Bind(room.levelNumber, room.roomNumber, generator.booksInRooms[room])); } Console.WriteLine("Cassandra: Data inserted."); }
public List <string> QueryBooksInRoom(RoomInfo room) { BoundStatement boundStatement = new BoundStatement(statementQueryBooksInRoom); RowSet results = session.Execute(boundStatement.Bind(room.levelNumber, room.roomNumber)); return(results.GetRows().Select(row => row.GetValue <string>("name")).ToList()); }
public List <RoomInfo> QueryConnections(RoomInfo room) { Console.WriteLine("Cassandra: Querying the database to find the rooms connected to {0}.", room); //PreparedStatement statementQueryConnections = session.Prepare("SELECT * FROM labyrinth.connections WHERE level1 = ? AND room1 = ?;"); BoundStatement boundStatement = new BoundStatement(statementQueryConnections); /* * RowSet results = session.Execute(string.Format( * "SELECT * FROM labyrinth.connections WHERE level1 = {0} AND room1 = {1};", * room.levelNumber, room.roomNumber)); */ RowSet results = session.Execute(boundStatement.Bind(room.levelNumber, room.roomNumber)); return(results.GetRows().Select(row => new RoomInfo(row.GetValue <int>("level2"), row.GetValue <int>("room2"))).ToList()); }
public void InsertData(Dictionary <RoomInfo, List <RoomInfo> > connections) { PreparedStatement statement = session.Prepare("INSERT INTO connections (level1, room1, level2, room2) VALUES (?, ?, ?, ?);"); foreach (var room1 in connections.Keys) { foreach (var room2 in connections[room1]) { /* * session.Execute(string.Format( * "INSERT INTO labyrinth.connections (level1, room1, level2, room2) VALUES ({0}, {1}, {2}, {3});", * room1.levelNumber, room1.roomNumber, room2.levelNumber, room2.roomNumber)); */ BoundStatement boundStatement = new BoundStatement(statement); session.Execute(boundStatement.Bind(room1.levelNumber, room1.roomNumber, room2.levelNumber, room2.roomNumber)); } } Console.WriteLine("Cassandra: Data inserted."); }
public List<Product> getProducts(string _itemID) { string strCQL = "SELECT priceAvail, productGroup, productSpec, sizeProfile " + "FROM products.itemsmaster " + "WHERE itemID=?"; PreparedStatement statement = session.Prepare(strCQL); BoundStatement boundStatement = new BoundStatement(statement); boundStatement.Bind(_itemID); //get result set from Cassandra RowSet results = session.Execute(boundStatement); List<Product> returnVal = new List<Product>(); foreach (Row row in results.GetRows()) { Product tempProd = new Product(); tempProd.itemID= _itemID; tempProd.priceAvail = row.GetValue<int>("priceavail"); tempProd.productGroup = row.GetValue<string>("productgroup"); tempProd.productSpec = row.GetValue<string>("productspec"); tempProd.sizeProfile = row.GetValue<string>("sizeprofile"); returnVal.Add(tempProd); } return returnVal; }
public override void LoadData() { PreparedStatement statement = Session.Prepare( "INSERT INTO simplex.songs " + "(id, title, album, artist, tags) " + "VALUES (?, ?, ?, ?, ?);"); BoundStatement boundStatement = new BoundStatement(statement); HashSet <String> tags = new HashSet <String>(); tags.Add("jazz"); tags.Add("2013"); Session.Execute(boundStatement.Bind( new Guid("756716f7-2e54-4715-9f00-91dcbea6cf50"), "La Petite Tonkinoise'", "Bye Bye Blackbird'", "Joséphine Baker", tags) ); tags = new HashSet <String>(); tags.Add("1996"); tags.Add("nirds"); Session.Execute(boundStatement.Bind( new Guid("f6071e72-48ec-4fcb-bf3e-379c8a696488"), "Die Mösch", "In Gold'", "Willi Ostermann", tags) ); tags = new HashSet <String>(); tags.Add("1970"); tags.Add("soundtrack"); Session.Execute(boundStatement.Bind( new Guid("fbdf82ed-0063-4796-9c7c-a3d4f47b4b25"), "Memo From Turner", "Performance", "Mick Jager", tags) ); // playlists table statement = Session.Prepare( "INSERT INTO simplex.playlists " + "(id, song_id, title, album, artist) " + "VALUES (?, ?, ?, ?, ?);"); boundStatement = new BoundStatement(statement); Session.Execute(boundStatement.Bind( new Guid("2cc9ccb7-6221-4ccb-8387-f22b6a1b354d"), new Guid("756716f7-2e54-4715-9f00-91dcbea6cf50"), "La Petite Tonkinoise", "Bye Bye Blackbird", "Joséphine Baker")); Session.Execute(boundStatement.Bind( new Guid("2cc9ccb7-6221-4ccb-8387-f22b6a1b354d"), new Guid("f6071e72-48ec-4fcb-bf3e-379c8a696488"), "Die Mösch", "In Gold", "Willi Ostermann")); Session.Execute(boundStatement.Bind( new Guid("3fd2bedf-a8c8-455a-a462-0cd3a4353c54"), new Guid("fbdf82ed-0063-4796-9c7c-a3d4f47b4b25"), "Memo From Turner", "Performance", "Mick Jager")); }
/// <summary> /// Creates a new BoundStatement object and bind its variables to the provided /// values. This method is a shortcut for <code>new /// BoundStatement(this).Bind(...)</code>. <p> Note that while no more /// <code>values</code> than bound variables can be provided, it is allowed to /// provide less <code>values</code> that there is variables. In that case, the /// remaining variables will have to be bound to values by another mean because /// the resulting <code>BoundStatement</code> being executable.</p> /// </summary> /// <param name="values"> the values to bind to the variables of the newly /// created BoundStatement. </param> /// /// <returns>the newly created <code>BoundStatement</code> with its variables /// bound to <code>values</code>. </returns> public BoundStatement Bind(params object[] values) { var bs = new BoundStatement(this); return(bs.Bind(values)); }
/// <summary> /// Creates a new BoundStatement object and bind its variables to the provided /// values. This method is a shortcut for <code>new /// BoundStatement(this).Bind(...)</code>. <p> Note that while no more /// <code>values</code> than bound variables can be provided, it is allowed to /// provide less <code>values</code> that there is variables. In that case, the /// remaining variables will have to be bound to values by another mean because /// the resulting <code>BoundStatement</code> being executable.</p> /// </summary> /// <param name="values"> the values to bind to the variables of the newly /// created BoundStatement. </param> /// /// <returns>the newly created <code>BoundStatement</code> with its variables /// bound to <code>values</code>. </returns> public BoundStatement Bind(params object[] values) { var bs = new BoundStatement(this); return bs.Bind(values); }