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


C# DbManager.QueryReader方法代码示例

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


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

示例1: Init


//.........这里部分代码省略.........
                        break;
                }
            }

            Previews.Sort();
            Previews.Reverse();

            dbstr = String.Format("server={0};database={1};userid={2};password={3};",
                                  DatabaseInfo.Host, DatabaseInfo.Name,
                                  DatabaseInfo.Username, DatabaseInfo.Password);

            Log.Debug(">>> Connecting to database...");

            try {
                dbcon = new MySqlConnection(dbstr);
                dbcon.Open();
            #if DEBUG
                DB.Query("TRUNCATE `file`");
                DB.Query("TRUNCATE `preview`");
            DB.Query("TRUNCATE `keyword`");
            DB.Query("TRUNCATE `keyword_rel`");
            #endif
                Log.Debug("OK!\n");
            }
            catch (Exception e) {
                Log.Debug("FAILED! ");
                Log.Werror("{0}\n", e.Message);
                return false;
            }

            var db = new DbManager();

            // Collect base paths from database
            if (db.QueryReader("SELECT * FROM base_path")) {
                while (db.DataReader.Read()) {
                    string p = db.DataReader.GetString("path");
                    long id = db.DataReader.GetInt64("id");

                    if (!(basePaths.Contains(p) && Tools.DirectoryExists(p))) {
                        Log.Notice("Base path \"{0}\" is removed from config or file " +
                                   "system! Removing from database...\n", p);
                        // NOTE! This uses the global DB object. It's not supposed to
                        // use the local one since it would conflict with the DataReader.
                        DB.Query("DELETE FROM base_path WHERE path = @path",
                                 DB.Param("path", p));
                    }
                    else
                        BasePaths.Add(new BasePath(id, p));
                }
            }

            // Sync paths from config file with path from database
            foreach (string path in basePaths) {
                var t = BasePaths.Find(delegate(BasePath tp) {
                    return tp.Name == path;
                });
                if (t == null) {
                    if (!Tools.DirectoryExists(path)) {
                        Log.Warning("Path \"{0}\" in config file doesn't exits in file " +
                                    "system!\n");
                    }
                    else {
                        Log.Debug("+++ Add {0} to base paths\n", path);
                        long myid;
                        string sql = "INSERT INTO base_path(path) VALUES (@path)";
                        // NOTE! This uses the global DB object. It's not supposed to
开发者ID:poppa,项目名称:MediaDB,代码行数:67,代码来源:Manager.cs

示例2: SaveKeywords

        private void SaveKeywords(long Id, string Keywords)
        {
            if (Keywords != null) {
            string[] keys = Keywords.Split(',');

            foreach (string key in keys) {
              string lowCaseKey = key.ToLower();
              int keyword_id = -1;

              using (var db = new DbManager(Manager.DbCon)) {
            string sql = "SELECT id FROM `keywords` WHERE [email protected]";
            db.QueryReader(sql, DB.Param("keyword", lowCaseKey));
            if (db.DataReader.HasRows) {
              db.DataReader.Read();
              keyword_id = (int)db.DataReader.GetValue(0);
            }
              }

              if (keyword_id == -1) {
            using (var dbinner = new DbManager(Manager.DbCon)) {
              long tmpkwdid;
              string sql = "INSERT INTO keywords (keyword) VALUES (@kwd)";
              dbinner.QueryInsert(out tmpkwdid, sql,
                                                DB.Param("kwd", lowCaseKey));
              keyword_id = (int)tmpkwdid;
            }
              }

              using (var dbinners = new DbManager(Manager.DbCon)) {
            long tmpid;
            string sql = "INSERT INTO keyword_rel (file_id,keyword_id) " +
                         "VALUES (@fileid,@keyid)";
            dbinners.QueryInsert(out tmpid, sql,
                                 DB.Param("fileid", Id),
                                 DB.Param("keyid", keyword_id));
              }
            }
            }
        }
开发者ID:poppa,项目名称:MediaDB,代码行数:39,代码来源:MediaFile.cs

示例3: GetMediaFile

        /// <summary>
        /// Get media file for <paramref name="fullname"/>.
        /// If it exists in the database the media file object will be
        /// populated. Otherwise an empty <see cref="MediaFile"/> object will
        /// be returned.
        /// </summary>
        /// <param name="fullname"></param>
        /// <returns></returns>
        public static MediaFile GetMediaFile(string fullname)
        {
            if (filesCount == 0) {
                return null;
            }

            MediaFile mf = null;
            //! TODO: I'm note sure what performance gain this lookup has. One thing
            //! is certain though: It's a pain keeping it in sync...
            if (FileIndex.Contains(fullname)) {
                // This method is called from an async method in Indexer.cs.
                // So lock during the DB call and release when db done.
                mutex.WaitOne();

                using (var db = new DbManager()) {
                    try {
                        string sql = "SELECT * FROM `file` WHERE fullname = @fn";
                        // Log.Debug("@@@ GetMEdiaFile({0})\n", sql.Replace("@fn", fullname));
                        if (db.QueryReader(sql, DB.Param("fn", fullname))) {
                            if (db.DataReader.HasRows) {
                                db.DataReader.Read();
                                mf = MediaFile.FromSql(db.DataReader);
                            }
                        }
                    }
                    catch (Exception e) {
                        Log.Warning("DB error: {0} {1}\n", e.Message, e.StackTrace);
                    }
                }

                // Release the thread
                mutex.ReleaseMutex();
            }
            return mf;
        }
开发者ID:poppa,项目名称:MediaDB,代码行数:43,代码来源:Manager.cs

示例4: SetFromSql

        /// <summary>
        /// Populate object from database record
        /// </summary>
        /// <param name="reader">
        /// A <see cref="MySqlDataReader"/>
        /// </param>
        public void SetFromSql(MySqlDataReader reader)
        {
            for (int i = 0; i < reader.FieldCount; i++) {
                switch (reader.GetName(i)) {
                    case "id": Id = reader.GetInt64(i); break;
                    case "name": Name = reader.GetString(i); break;
                    case "fullname": FullName = reader.GetString(i); break;
                    case "sha1_hash": sha1Hash = reader.GetString(i); break;
                    case "directory_id": DirectoryId = reader.GetInt64(i); break;
                    case "mimetype": Mimetype = reader.GetString(i); break;
                    case "title":
                        Title = DB.IsNull(reader[i]) ? null : reader.GetString(i);
                        break;
                    case "description":
                        Description = DB.IsNull(reader[i]) ? null : reader.GetString(i);
                        break;
                    case "copyright":
                        Copyright = DB.IsNull(reader[i]) ? null : reader.GetString(i);
                        break;
                    case "width": Width = reader.GetInt32(i); break;
                    case "height": Height = reader.GetInt32(i); break;
                    case "size": Size = reader.GetInt64(i); break;
                    case "resolution": Resolution = reader.GetDouble(i); break;
                    case "exif":
                        Exif = DB.IsNull(reader[i]) ? null : reader.GetString(i);
                        break;
                    case "created": Created = reader.GetDateTime(i); break;
                    case "modified":
                        if (!DB.IsNull(reader[i]))
                            Modified = reader.GetDateTime(i);
                        break;
                    case "keywords":
                        Keywords = DB.IsNull(reader[i]) ? null : reader.GetString(i);
                        break;
                }
            }

            if (Id > 0) {
                using (var db = new DbManager(Manager.DbCon)) {
                    var sql = "SELECT * FROM `preview` WHERE [email protected]";
                    if (db.QueryReader(sql, DB.Param("id", Id))) {
                        while (db.DataReader.NextResult()) {
                            db.DataReader.Read();
                            Previews.Add(PreviewFile.FromSql(db.DataReader));
                        }
                    }
                }
            }
        }
开发者ID:poppa,项目名称:MediaDB,代码行数:55,代码来源:MediaFile.cs


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