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


C# DbManager.QueryInsert方法代码示例

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


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

示例1: 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

示例2: Save

        /// <summary>
        /// Save to database. Inserts if new, updates otherwise
        /// </summary>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        public bool Save()
        {
            if (Id == 0) {
                string sql = "INSERT INTO `file` (name, fullname, directory_id,"       +
                             " mimetype, title, description, copyright, width, height,"+
                             " size, resolution, exif, created, modified, keywords, "  +
                             " sha1_hash) "                                            +
                             "VALUES (@name, @fullname, @directory_id, @mimetype,"     +
                             " @title, @description, @copyright, @width, @height,"     +
                             " @size, @resolution, @exif, @created, @modified, "       +
                             " @keywords, @sha1_hash)";

                long tmpid;
                object mddate = null;
                if (Modified != Manager.NullDate)
                    mddate = Modified;
                var db = new DbManager(Manager.DbCon);
                if (db.QueryInsert(out tmpid, sql,
                                   DB.Param("name", Name),
                                   DB.Param("fullname", FullName),
                                   DB.Param("directory_id", DirectoryId),
                                   DB.Param("mimetype", Mimetype),
                                   DB.Param("title", Title),
                                   DB.Param("description", Description),
                                   DB.Param("copyright", Copyright),
                                   DB.Param("width", Width),
                                   DB.Param("height", Height),
                                   DB.Param("size", Size),
                                   DB.Param("resolution", Resolution),
                                   DB.Param("exif", Exif),
                                   DB.Param("created", Created),
                                   DB.Param("modified", mddate),
                                   DB.Param("keywords", Keywords),
                                                     DB.Param("sha1_hash", Sha1Hash)))
                {
                    Id = tmpid;

              SaveKeywords(Id, Keywords);

                    // Update the file index in Manager
                    Manager.AddToFileIndex(FullName);

                    foreach (PreviewFile f in Previews) {
                        f.FileId = Id;
                        if (!f.Save()) {
                            Log.Warning("  >>> Failed inserting preview \"{0}\" for " +
                                        "\"{1}\"\n", f.Name, FullName);
                        }
                    }

                    db.Dispose();
                    return true;
                }
                else {
                    Log.Debug("Failed inserting {0} into database!\n", FullName);
                    db.Dispose();
                    return false;
                }
            }
            else {
                // To regenerate hash
                sha1Hash = null;

                DB.Query("DELETE FROM `preview` WHERE [email protected]",
                                 DB.Param("id", Id));

                string sql = "UPDATE `file` SET "           +
                                         " [email protected]_hash,"       +
                                         " [email protected],"                 +
                                         " [email protected],"         +
                                         " [email protected]_id," +
                                         " [email protected],"         +
                                         " [email protected],"               +
                                         " [email protected],"   +
                                         " [email protected],"       +
                                         " [email protected],"               +
                                         " [email protected],"             +
                                         " [email protected],"     +
                                         " [email protected],"                 +
                                         " m[email protected],"         +
                                         " [email protected] "         +
                                         "WHERE [email protected]";

                if (DB.Query(sql, DB.Param("sha1_hash", Sha1Hash),
                                  DB.Param("name", Name),
                                  DB.Param("fullname", FullName),
                                  DB.Param("directory_id", DirectoryId),
                                                    DB.Param("mimetype", Mimetype),
                                                    DB.Param("title", Title),
                                                    DB.Param("description", Description),
                                                    DB.Param("copyright", Copyright),
                                                    DB.Param("width", Width),
                                                    DB.Param("height", Height),
                                                    DB.Param("resolution", Resolution),
//.........这里部分代码省略.........
开发者ID:poppa,项目名称:MediaDB,代码行数:101,代码来源:MediaFile.cs


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