本文整理汇总了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));
}
}
}
}
示例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),
//.........这里部分代码省略.........