当前位置: 首页>>代码示例>>C#>>正文


C# ISession.Prepare方法代码示例

本文整理汇总了C#中ISession.Prepare方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.Prepare方法的具体用法?C# ISession.Prepare怎么用?C# ISession.Prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISession的用法示例。


在下文中一共展示了ISession.Prepare方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ForumRepository

        /// <summary>
        /// Create a new instance of the repository with the session as a dependency
        /// </summary>
        public ForumRepository(ISession session)
        {
            this.Session = session;

            _insertTopicStatement = Session.Prepare("INSERT INTO topics (topic_id, topic_title, topic_date) VALUES (?, ?, ?)");
            _insertMessageStatement = Session.Prepare("INSERT INTO messages (topic_id, message_date, message_body) VALUES (?, ?, ?)");
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:10,代码来源:ForumRepository.cs

示例2: addToTempPlaylist

        public bool addToTempPlaylist(Playlist playlist,ISession session)
        {
            try
            {
                // Prepare and bind statement passing in the relevant fields
                String todo = ("insert into playlist (track_id,playlist_id,track_pos)\n" +
                 "values (:tid, :pid,:tpos) if not exists using ttl 3600;");
                PreparedStatement ps = session.Prepare(todo);

                // Getting Appropriate ID's for query
                Guid pid = playlist.getID();

                List<Song> songs = playlist.getSongs();

                for (int i = 0; i < songs.Count(); i++)
                {
                    Guid tid = songs[i].getSongID();
                    int pos = getListPos(session, tid, pid);
                    BoundStatement bs = ps.Bind(tid, pid, pos);
                    // Execute Query
                    session.Execute(bs);
                }

                return false;
                // Catch exceptions
            }
            catch (Exception ex)
            {
                Console.WriteLine("SOMETHING WENT WRONG add to temp playlist: " + ex.Message);
                return false;
            }
        }
开发者ID:andrewdavis1995,项目名称:MALTMusic,代码行数:32,代码来源:PlaylistModel.cs

示例3: SetupSessionAndCluster

        private ITestCluster SetupSessionAndCluster(int nodes, Dictionary<string, string> replication = null)
        {
            ITestCluster testCluster = TestClusterManager.GetTestCluster(nodes);
            _session = testCluster.Session;
            _ksName = TestUtils.GetUniqueKeyspaceName();
            _session.CreateKeyspace(_ksName, replication);
            TestUtils.WaitForSchemaAgreement(_session.Cluster);
            _session.ChangeKeyspace(_ksName);
            _table = new Table<ManyDataTypesEntity>(_session, new MappingConfiguration());
            _table.Create();
            _defaultPocoList = ManyDataTypesEntity.GetDefaultAllDataTypesList();
            _preparedStatement = _session.Prepare(_preparedInsertStatementAsString);
            foreach (var manyDataTypesEntity in _defaultPocoList)
                _session.Execute(GetBoundInsertStatementBasedOnEntity(manyDataTypesEntity));

            return testCluster;
        }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:17,代码来源:ConsistencyTests.cs

示例4: doInsertTrack

        /*
         * Function to attempt log in to a user account
         * @PARAMETERS: - song: the song to add
         * @RETURNS: The User who has been logged in - null if unsuccesful
         * @AUTHORS: Andrew Davis and Matt Malone
         * NOTE - Commented code left in by Matt - just in case it breaks
         */
        public bool doInsertTrack(Song song, ISession session)
        {
            try
            {
                // Call to initialise cluster connection
                //init();

                ///

                Guid tid = song.getSongID();
                String artist = song.getArtist();
                String album = song.getAlbum();
                int year = song.getYear();
                String genre = song.getGenre();
                String file_loc = song.getFileLocation();
                int length = song.getLength();
                String trackname = song.getTrackName();

                // Connect to cluster
                //ISession session = cluster.Connect("maltmusic");

                //Guid tid = Guid.NewGuid();

                // Prepare and bind statement passing in username
                String todo = ("insert into tracks (\n" +
                  "track_id, artist, album, year,genre, file_loc,length,track_name)\n" +
                 "values (:tid, :art,:alb,:yr,:gnr,:floc,:len,:tnm) if not exists");

                PreparedStatement ps = session.Prepare(todo);

                BoundStatement bs = ps.Bind(tid, artist, album, year, genre, file_loc, length, trackname);

                // Execute Query
                session.Execute(bs);
                //session.Dispose();
                return true;

                // Catch exceptions
            }
            catch (Exception ex)
            {
                Console.WriteLine("SOMETHING WENT WRONG in INSERT TRACK: " + ex.Message);
                return false;
            }
        }
开发者ID:andrewdavis1995,项目名称:MALTMusic,代码行数:52,代码来源:SongModel.cs

示例5: PrepareQuery

 internal static PreparedStatement PrepareQuery(ISession session, string query, string messageInstead = null)
 {
     PreparedStatement ret = session.Prepare(query);
     return ret;
 }
开发者ID:mtf30rob,项目名称:csharp-driver,代码行数:5,代码来源:QueryTools.cs

示例6: getTracksInPlist

        /// <summary>
        ///     Get the songs from a playlist
        /// </summary>
        /// <param name="pid">the id of the playlist</param>
        /// <param name="session">the session for connecting to Cassandra</param>
        /// <returns></returns>
        public List<Song> getTracksInPlist(Guid pid, ISession session)
        {
            List<Song> songs = new List<Song>();
            List<int> positions = new List<int>();

            String todo = ("select * from playlist where playlist_id = :pid");
            PreparedStatement ps = session.Prepare(todo);
            BoundStatement bs = ps.Bind(pid);
            // Execute Query
            RowSet rows = session.Execute(bs);
            foreach (Row row in rows)
            {
                //under duress i do this
                Guid tid = (Guid)row["track_id"];

                int pos = (int)row["track_pos"];
                positions.Add(pos);

                String things = ("select * from tracks where track_id = :tid");
                PreparedStatement prep = session.Prepare(things);
                BoundStatement bound = prep.Bind(tid);
                // Execute Query
                RowSet rows2 = session.Execute(bound);

                foreach (Row rowset in rows2)
                {
                    //this one
                    //public Song(String artist, String location, String name, Guid tid)
                    String name = (String)rowset["track_name"];
                    String artist = (String)rowset["artist"];
                    String file_loc = (String)rowset["file_loc"];
                    int length = (int)rowset["length"];
                    int year = (int)rowset["year"];
                    String album = rowset["album"].ToString();
                    String genre = rowset["genre"].ToString();

                    Song toadd = new Song(artist, album, year, genre, file_loc, length, name, tid);
                    songs.Add(toadd);
                }
            }

            // SORT

            List<Song> sortedSongs = new List<Song>();

            while (positions.Count > 0 && songs.Count > 0)
            {
                int currentLowest = positions[0];
                int lowestIndex = 0;

                for (int i = 0; i < positions.Count; i++)
                {
                    if (positions[i] < currentLowest)
                    {
                        currentLowest = positions[i];
                        lowestIndex = i;
                    }
                }

                sortedSongs.Add(songs[lowestIndex]);

                songs.RemoveAt(lowestIndex);
                positions.RemoveAt(lowestIndex);

            }

            return sortedSongs;
        }
开发者ID:andrewdavis1995,项目名称:MALTMusic,代码行数:74,代码来源:PlaylistModel.cs

示例7: getListPos

        public int getListPos(ISession session, Guid tid, Guid pid)
        {
            int pos = -1;

            //String todo = ("select * from playlist where track_id = :tid and playlist_id = :pid");

            String todo = ("select * from playlist where playlist_id = :pid");

            PreparedStatement ps = session.Prepare(todo);
            //BoundStatement bs = ps.Bind(tid, pid);
            BoundStatement bs = ps.Bind(pid);
            // Execute Query
            RowSet rows = session.Execute(bs);

            List<int> li = new List<int>();

            // When the username finds a match...
            foreach (Row row in rows)
            {

                if (row["track_pos"] != null)
                {
                    int x = (int)row["track_pos"];
                    li.Add(x);
                }
                else
                {
                    return 0;
                }
            }
            //get length of list
            int y = li.Count();

            //if list not empty
            if (y != 0)
            {
                //set init highest value
                int max = li[0];
                //for each value in list check against current highest
                for (int x = 0; x < y; x++)
                {
                    if (li[x] > max)
                    {
                        //If larger than current, set max to new highest
                        max = li[x];
                    }

                }
                pos = max + 1;
                return pos;
            }
            else
            {
                pos = 0;
                return pos;
            }
        }
开发者ID:andrewdavis1995,项目名称:MALTMusic,代码行数:57,代码来源:PlaylistModel.cs

示例8: updateVoteCountForUser

 public void updateVoteCountForUser(Guid tid, String voter, int voteType, ISession session)
 {
     String vtype;
     if (voteType == 1)
     {
         vtype = "up";
     }
     else if (voteType == -1)
     {
         vtype = "down";
     }
     else
     {
         Console.WriteLine("ERRORS Occurring");
         return;
     }
     // Prepare and bind statement passing in things
     String todo = ("insert into user_votes (track_id, voter, howvoted) values (:tid, :vtr, :hwvt) if not exists");
     PreparedStatement ps = session.Prepare(todo);
     BoundStatement bs = ps.Bind(tid, voter, vtype);
     // Execute Query
     session.Execute(bs);
 }
开发者ID:andrewdavis1995,项目名称:MALTMusic,代码行数:23,代码来源:VoteModel.cs

示例9: CQLInventoryStorage

        public CQLInventoryStorage(string[] contactPoints)
        {
            _cluster = Cluster.Builder().AddContactPoints(contactPoints).Build();
            _session = _cluster.Connect(KEYSPACE_NAME);

            SKEL_SELECT_STMT = _session.Prepare("SELECT * FROM skeletons WHERE user_id = ?;");
            SKEL_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            SKEL_SINGLE_SELECT_STMT = _session.Prepare("SELECT * FROM skeletons WHERE user_id = ? AND folder_id = ?;");
            SKEL_SINGLE_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            SKEL_INSERT_STMT
                = _session.Prepare( "INSERT INTO skeletons (user_id, folder_id, folder_name, parent_id, type, level) " +
                                    "VALUES(?, ?, ?, ?, ?, ?);");
            SKEL_INSERT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_SELECT_STMT = _session.Prepare("SELECT * FROM folder_contents WHERE folder_id = ?;");
            FOLDER_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_ATTRIB_SELECT_STMT = _session.Prepare(   "SELECT * FROM folder_contents WHERE folder_id = ? AND item_id = "
                                                            + FOLDER_MAGIC_ENTRY.ToString() + ";");
            FOLDER_ATTRIB_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_ATTRIB_INSERT_STMT
                = _session.Prepare( "INSERT INTO folder_contents (folder_id, item_id, name, inv_type, creation_date, owner_id) " +
                                    "VALUES (?, ?, ?, ?, ?, ?);");
            FOLDER_ATTRIB_INSERT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_ITEM_INSERT_STMT
                = _session.Prepare( "INSERT INTO folder_contents (folder_id, item_id, name, asset_id, asset_type, " +
                                        "base_permissions, creation_date, creator_id, current_permissions, description, " +
                                        "everyone_permissions, flags, group_id, group_owned, group_permissions, " +
                                        "inv_type, next_permissions, owner_id, sale_type) " +
                                    "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
            FOLDER_ITEM_INSERT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_ITEM_UPDATE_STMT
                = _session.Prepare("UPDATE folder_contents SET name = ?, asset_id = ?, asset_type = ?, " +
                                        "base_permissions = ?, creation_date = ?, creator_id = ?, current_permissions= ?, description = ?, " +
                                        "everyone_permissions = ?, flags = ?, group_id = ?, group_owned = ?, group_permissions = ?, " +
                                        "inv_type = ?, next_permissions = ?, sale_type = ? " +
                                    "WHERE folder_id = ? AND item_id = ?;");
            FOLDER_ITEM_UPDATE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_ITEM_REMOVE_STMT = _session.Prepare("DELETE FROM folder_contents WHERE folder_id = ? AND item_id = ?;");
            FOLDER_ITEM_REMOVE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_VERSION_INC_STMT
                = _session.Prepare("UPDATE folder_versions SET version = version + 1 WHERE user_id = ? AND folder_id = ?;");
            FOLDER_VERSION_INC_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_VERSION_SELECT_STMT = _session.Prepare("SELECT * FROM folder_versions WHERE user_id = ?;");
            FOLDER_VERSION_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_VERSION_SINGLE_SELECT_STMT = _session.Prepare("SELECT * FROM folder_versions WHERE user_id = ? AND folder_id = ?;");
            FOLDER_VERSION_SINGLE_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_UPDATE_STMT = _session.Prepare(  "UPDATE folder_contents SET name = ?, inv_type = ? " +
                                                    "WHERE folder_id = ? AND item_id = " + FOLDER_MAGIC_ENTRY.ToString());
            FOLDER_UPDATE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            SKEL_UPDATE_STMT = _session.Prepare("UPDATE skeletons SET folder_name = ?, type = ? WHERE user_id = ? AND folder_id = ?;");
            SKEL_UPDATE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            SKEL_MOVE_STMT = _session.Prepare("UPDATE skeletons SET parent_id = ? WHERE user_id = ? AND folder_id = ?;");
            SKEL_MOVE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            ITEM_OWNERSHIP_INSERT = _session.Prepare("INSERT INTO item_parents(item_id, parent_folder_id) VALUES(?, ?);");
            ITEM_OWNERSHIP_INSERT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            ITEM_OWNERSHIP_UPDATE = _session.Prepare("UPDATE item_parents SET parent_folder_id = ? WHERE item_id = ?;");
            ITEM_OWNERSHIP_UPDATE.SetConsistencyLevel(ConsistencyLevel.Quorum);

            ITEM_OWNERSHIP_REMOVE = _session.Prepare("DELETE FROM item_parents WHERE item_id = ?;");
            ITEM_OWNERSHIP_REMOVE.SetConsistencyLevel(ConsistencyLevel.Quorum);

            ITEM_OWNERSHIP_SELECT = _session.Prepare("SELECT * FROM item_parents WHERE item_id = ?;");
            ITEM_OWNERSHIP_SELECT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_ITEM_SELECT_STMT = _session.Prepare("SELECT * FROM folder_contents WHERE folder_id = ? AND item_id = ?;");
            FOLDER_ITEM_SELECT_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_REMOVE_STMT = _session.Prepare("DELETE FROM folder_contents WHERE folder_id = ?;");
            FOLDER_REMOVE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            SKEL_REMOVE_STMT = _session.Prepare("DELETE FROM skeletons WHERE user_id = ? AND folder_id = ?;");
            SKEL_REMOVE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);

            FOLDER_VERSION_REMOVE_STMT = _session.Prepare("DELETE FROM folder_versions WHERE user_id = ? AND folder_id = ?;");
            FOLDER_VERSION_REMOVE_STMT.SetConsistencyLevel(ConsistencyLevel.Quorum);
        }
开发者ID:AlphaStaxLLC,项目名称:opensim-cql-inventory,代码行数:91,代码来源:CQLInventoryStorage.cs

示例10: insertToWeather

 public void insertToWeather(Guid tid, HashSet<String> tags, ISession session)
 {
     try
     {
         // Prepare and bind statement
         String todo = ("insert into weathertags (track_id, tags) values (:tid, :tag) if not exists");
         PreparedStatement ps = session.Prepare(todo);
         BoundStatement bs = ps.Bind(tid, tags);
         // Execute Query
         session.Execute(bs);
         return;
         // Catch exceptions
     }
     catch (Exception ex)
     {
         Console.WriteLine("SOMETHING WENT WRONG in INSERT TRACK: " + ex.Message);
         return;
     }
 }
开发者ID:andrewdavis1995,项目名称:MALTMusic,代码行数:19,代码来源:SongModel.cs


注:本文中的ISession.Prepare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。