本文整理汇总了C#中Row.GetDataStoreKey方法的典型用法代码示例。如果您正苦于以下问题:C# Row.GetDataStoreKey方法的具体用法?C# Row.GetDataStoreKey怎么用?C# Row.GetDataStoreKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Row
的用法示例。
在下文中一共展示了Row.GetDataStoreKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: crudUpdate
private static int crudUpdate(MySQLDataStoreBase store, MySqlConnection cnn, MySqlTransaction trans, Row row, IDataStoreKey key, FieldFilterFunc filter)
{
var target = store.TargetName;
var values = new StringBuilder();
var vparams = new List<MySqlParameter>();
var vpidx = 0;
foreach (var fld in row.Schema.FieldDefs)
{
var fattr = fld[target];
if (fattr==null) continue;
var fname = fld.GetBackendNameForTarget(target);
//20141008 DKh Skip update of key fields
//20160124 DKh add update of keys if IDataStoreKey is present
if (fattr.Key && !GeneratorUtils.HasFieldInNamedKey(fname, key)) continue;
if (fattr.StoreFlag != StoreFlag.LoadAndStore && fattr.StoreFlag != StoreFlag.OnlyStore) continue;
if (filter!=null)//20160210 Dkh+SPol
{
if (!filter(row, key, fld)) continue;
}
var fvalue = getFieldValue(row, fld.Order, store);
if ( fvalue != null)
{
var pname = string.Format("?VAL{0}", vpidx);
values.AppendFormat(" `{0}` = {1},", fname, pname);
var par = new MySqlParameter();
par.ParameterName = pname;
par.Value = fvalue;
vparams.Add(par);
vpidx++;
}
else
{
values.AppendFormat(" `{0}` = NULL,", fname);
}
}//foreach
if (values.Length > 0)
{
values.Remove(values.Length - 1, 1);// remove ","
}
else
return 0;//nothing to do
string tableName = getTableName(row.Schema, target);
using(var cmd = cnn.CreateCommand())
{
var sql = string.Empty;
var pk = key ?? row.GetDataStoreKey(target);
if (pk == null)
throw new MySQLDataAccessException(StringConsts.KEY_UNAVAILABLE_ERROR);
var where = GeneratorUtils.KeyToWhere(pk, cmd.Parameters);
if (!string.IsNullOrEmpty(where))
sql = "UPDATE `{0}` T1 SET {1} WHERE {2}".Args( tableName, values, where);
else
throw new MySQLDataAccessException(StringConsts.BROAD_UPDATE_ERROR);//20141008 DKh BROAD update
cmd.Transaction = trans;
cmd.CommandText = sql;
cmd.Parameters.AddRange(vparams.ToArray());
ConvertParameters(store, cmd.Parameters);
try
{
var affected = cmd.ExecuteNonQuery();
GeneratorUtils.LogCommand(store.LogLevel, "update-ok", cmd, null);
return affected;
}
catch(Exception error)
{
GeneratorUtils.LogCommand(store.LogLevel, "update-error", cmd, error);
throw;
}
}//using command
}
示例2: crudDelete
private static int crudDelete(MySQLDataStoreBase store, MySqlConnection cnn, MySqlTransaction trans, Row row, IDataStoreKey key)
{
var target = store.TargetName;
string tableName = getTableName(row.Schema, target);
using (var cmd = cnn.CreateCommand())
{
var pk = key ?? row.GetDataStoreKey(target);
if (pk == null)
throw new MySQLDataAccessException(StringConsts.KEY_UNAVAILABLE_ERROR);
var where = GeneratorUtils.KeyToWhere(pk, cmd.Parameters);
cmd.Transaction = trans;
if (!string.IsNullOrEmpty(where))
cmd.CommandText = string.Format("DELETE T1 FROM `{0}` T1 WHERE {1}",tableName, where);
else
cmd.CommandText = string.Format("DELETE T1 FROM `{0}` T1", tableName);
ConvertParameters(store, cmd.Parameters);
try
{
var affected = cmd.ExecuteNonQuery();
GeneratorUtils.LogCommand(store.LogLevel, "delete-ok", cmd, null);
return affected;
}
catch(Exception error)
{
GeneratorUtils.LogCommand(store.LogLevel, "delete-error", cmd, error);
throw;
}
}//using command
}