本文整理汇总了C#中System.Data.Common.DbCommand.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# DbCommand.GetType方法的具体用法?C# DbCommand.GetType怎么用?C# DbCommand.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Common.DbCommand
的用法示例。
在下文中一共展示了DbCommand.GetType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CacheOracleDbTypeEnumValues
protected virtual void CacheOracleDbTypeEnumValues(DbCommand command) {
var assembly = command.GetType().GetTypeInfo().Assembly;
var typeEnum = assembly.GetType(OracleDbTypeEnumName);
ReflectionCache.DbTypeRefCursor = Enum.Parse(typeEnum, "RefCursor");
ReflectionCache.DbTypeBlob = Enum.Parse(typeEnum, "Blob");
ReflectionCache.DbTypeDate = Enum.Parse(typeEnum, "Date");
}
示例2: EnsureOracleBindByName
private static void EnsureOracleBindByName(DbCommand cmd)
{
//Oracle.DataAccess.Client only binds first parameter match unless BindByName=true
//so we violate LiskovSP (in reflection to avoid dependency on ODP)
if (cmd.GetType().GetProperty("BindByName") != null)
{
cmd.GetType().GetProperty("BindByName").SetValue(cmd, true, null);
}
}
示例3: PrepareParameterScale
static internal Exception PrepareParameterScale(DbCommand cmd, string type)
{
return InvalidOperation(Res.GetString(Res.ADP_PrepareParameterScale, cmd.GetType().Name, type));
}
示例4: Query
public DataTable Query( DbCommand cmd )
{
if ( cmd == null )
{
throw new ArgumentNullException( "cmd" );
}
SQLiteCommand sqliteCmd = cmd as SQLiteCommand;
if ( cmd == null )
{
throw new ArgumentException( "command has invalid type: " + cmd.GetType() );
}
Open( false );
if ( sqliteCmd.Connection != myConnection )
{
sqliteCmd.Connection = myConnection;
}
// TODO: use:
// DbDataReader reader = cmd.ExecuteReader();
// table.Load( reader );
SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter( sqliteCmd );
DataTable table = new DataTable();
table.Locale = CultureInfo.InvariantCulture;
dataAdapter.Fill( table );
return table;
}
示例5: DatabaseEngineIs
protected virtual bool DatabaseEngineIs(DbCommand command, params System.String[] flavors)
{
return DatabaseEngineIs(command.GetType().FullName, flavors);
}
示例6: GetParameterFormat
/// <summary>
/// Gets the format of the parameter, to avoid query the schema the parameter
/// format is cached with the type of the parameter. This version is used
/// for the old interface of DataAccess based on anonimous function.
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
private static String GetParameterFormat(DbCommand command)
{
String typeName = command.GetType().FullName;
if (!mParametersFormat.ContainsKey(typeName))
{
mParametersFormat.Add(typeName,
command.Connection.GetSchema("DataSourceInformation")
.Rows[0]["ParameterMarkerFormat"].ToString());
}
return mParametersFormat[typeName];
}
示例7: PrepareParameterSize
internal static Exception PrepareParameterSize(DbCommand cmd)
{
return InvalidOperation(Res.GetString(Res.ADP_PrepareParameterSize, cmd.GetType().Name));
}
示例8: ConfigureCommandForSelect
private void ConfigureCommandForSelect(DbCommand command, ViewPage page, SelectClauseDictionary expressions, string fromClause, string whereClause, string orderByClause, CommandConfigurationType commandConfiguration)
{
bool useServerPaging = ((commandConfiguration != CommandConfigurationType.SelectDistinct && !(_serverRules.EnableResultSet)) && (commandConfiguration != CommandConfigurationType.SelectAggregates && commandConfiguration != CommandConfigurationType.SelectFirstLetters));
bool useLimit = SupportsLimitInSelect(command);
bool useSkip = SupportsSkipInSelect(command);
if (useServerPaging)
page.AcceptAllRows();
StringBuilder sb = new StringBuilder();
if (useLimit || useSkip)
useServerPaging = false;
bool countUsingHierarchy = false;
if ((commandConfiguration == CommandConfigurationType.SelectCount) && (useServerPaging && RequiresHierarchy(page)))
{
countUsingHierarchy = true;
commandConfiguration = CommandConfigurationType.Select;
}
if (commandConfiguration == CommandConfigurationType.SelectExisting)
useServerPaging = false;
if (commandConfiguration == CommandConfigurationType.SelectCount)
sb.AppendLine("select count(*)");
else
{
if (useServerPaging)
sb.AppendLine("with page_cte__ as (");
else
if ((commandConfiguration == CommandConfigurationType.Sync) && useLimit)
sb.Append("select * from (select @row_num := @row_num+1 row_number__,cte__.* from (select @r" +
"ow_num:=0) r,(");
sb.AppendLine("select");
if (useServerPaging)
AppendRowNumberExpression(sb, page, expressions, orderByClause);
if (commandConfiguration == CommandConfigurationType.SelectDistinct)
{
DataField distinctField = page.FindField(page.DistinctValueFieldName);
string distinctExpression = expressions[distinctField.ExpressionName()];
if (distinctField.Type.StartsWith("Date"))
{
string commandType = command.GetType().ToString();
if (commandType == "System.Data.SqlClient.SqlCommand")
distinctExpression = String.Format("DATEADD(dd, 0, DATEDIFF(dd, 0, {0}))", distinctExpression);
if (commandType == "MySql.Data.MySqlClient.MySqlCommand")
distinctExpression = String.Format("cast({0} as date)", distinctExpression);
}
sb.AppendFormat("distinct {0} \"{1}\"\r\n", distinctExpression, page.DistinctValueFieldName);
}
else
if (commandConfiguration == CommandConfigurationType.SelectAggregates)
AppendAggregateExpressions(sb, page, expressions);
else
if (commandConfiguration == CommandConfigurationType.SelectFirstLetters)
{
string substringFunction = "substring";
if (DatabaseEngineIs(command, "Oracle", "DB2"))
substringFunction = "substr";
AppendFirstLetterExpressions(sb, page, expressions, substringFunction);
}
else
{
if ((commandConfiguration == CommandConfigurationType.Select) && useSkip)
sb.AppendFormat(" first {0} skip {1}\r\n", page.PageSize, (page.PageSize * page.PageIndex));
if ((commandConfiguration == CommandConfigurationType.Sync) && useSkip)
{
// Only select the primary key.
foreach (DataField field in page.Fields)
if (field.IsPrimaryKey)
{
sb.Append(expressions[field.ExpressionName()]);
break;
}
}
else
if (commandConfiguration == CommandConfigurationType.SelectExisting)
sb.AppendLine("*");
else
AppendSelectExpressions(sb, page, expressions, !(useServerPaging));
}
}
sb.AppendLine("from");
sb.AppendLine(fromClause);
_hasWhere = false;
if (String.IsNullOrEmpty(_viewFilter))
{
_viewFilter = _view.GetAttribute("filter", String.Empty);
if (String.IsNullOrEmpty(_viewFilter) && ((_viewType == "Form") && !(String.IsNullOrEmpty(page.LastView))))
{
XPathNavigator lastView = _config.SelectSingleNode("/c:dataController/c:views/c:view[@id=\'{0}\']", page.LastView);
if (lastView != null)
_viewFilter = lastView.GetAttribute("filter", String.Empty);
}
}
if (!(String.IsNullOrEmpty(_viewFilter)))
_viewFilter = String.Format("({0})", _viewFilter);
if (commandConfiguration == CommandConfigurationType.SelectExisting)
{
EnsureWhereKeyword(sb);
sb.Append(expressions[page.InnerJoinForeignKey.ToLower()]);
sb.Append("=");
sb.Append(page.InnerJoinPrimaryKey);
sb.AppendLine(" and ");
}
//.........这里部分代码省略.........
示例9: InitSetBindByName
private static MethodInfo InitSetBindByName(DbCommand command)
{
return command.GetType().GetMethod("set_BindByName", BindingFlags.Public | BindingFlags.Instance);
}
示例10: EscapePattern
public static string EscapePattern(DbCommand command, string s)
{
if (String.IsNullOrEmpty(s))
return s;
if (command.GetType().FullName == "System.Data.SqlClient.SqlCommand")
return _sqlClientPatternEscape.Replace(s, "[$1]");
return s;
}
示例11: AddDbCommandStatements
private void AddDbCommandStatements (CodeMemberMethod m,
CodeExpression expr,
DbCommand cmd)
{
if (cmd == null)
return;
CodeExpression expr1;
CodeStatement stmt = Let (expr, New (cmd.GetType ()));
m.Statements.Add (stmt);
stmt = Let (PropRef (expr,"Connection"), PropRef ("Connection"));
m.Statements.Add (stmt);
stmt = Let (PropRef (expr, "CommandText"), Const (cmd.CommandText));
m.Statements.Add (stmt);
expr1 = PropRef (Local(typeof (CommandType).FullName), cmd.CommandType.ToString ());
stmt = Let (PropRef (expr, "CommandType"), expr1);
m.Statements.Add (stmt);
expr1 = PropRef (expr, "Parameters");
foreach (DbParameter param in cmd.Parameters) {
AddDbParameterStatements (m, expr1, param);
}
}
示例12: CreateDBCommandCollectionFieldAndProperty
private void CreateDBCommandCollectionFieldAndProperty (CodeTypeDeclaration t, DbCommand cmd)
{
CodeExpression expr;
CodeStatement setStmt;
CodeStatement stmt;
CodeMemberField f = new CodeMemberField ();
f.Name = "_commandCollection";
f.Type = TypeRefArray (cmd.GetType (), 1);
t.Members.Add (f);
CodeMemberProperty p = new CodeMemberProperty ();
p.Name = "CommandCollection";
p.Attributes = MemberAttributes.Family;
p.Type = f.Type;
p.HasSet = false;
expr = FieldRef ("_commandCollection");
setStmt = Eval (MethodInvoke ("InitCommandCollection"));
stmt = new CodeConditionStatement (Equals (expr, Const (null)),
new CodeStatement [] {setStmt},
new CodeStatement [] {});
p.GetStatements.Add (stmt);
p.GetStatements.Add (Return (expr));
t.Members.Add (p);
}
示例13: AppendFilterExpressionsToWhere
//.........这里部分代码省略.........
{
string exactFlag = "=";
if (String.IsNullOrEmpty(m.Groups["Quote"].Value))
exactFlag = " ";
string negativeFlag = " ";
if (negativeSample)
{
negativeFlag = "-";
negativeSample = false;
}
words.Add(String.Format("{0}{1}{2}", negativeFlag, exactFlag, m.Groups["Value"].Value));
}
m = m.NextMatch();
}
bool firstPhrase = true;
foreach (List<String> phrase in phrases)
if (phrase.Count > 0)
{
if (firstPhrase)
firstPhrase = false;
else
sb.AppendLine("or");
sb.AppendLine("(");
bool firstWord = true;
System.DateTime paramValueAsDate;
foreach (string paramValueWord in phrase)
{
bool negativeFlag = (paramValueWord[0] == '-');
bool exactFlag = (paramValueWord[1] == '=');
string comparisonOperator = "like";
if (exactFlag)
comparisonOperator = "=";
string pv = paramValueWord.Substring(2);
bool paramValueIsDate = SqlStatement.TryParseDate(command.GetType(), pv, out paramValueAsDate);
bool firstTry = true;
DbParameter parameter = null;
if (!(paramValueIsDate))
pv = SqlStatement.EscapePattern(command, pv);
double paramValueAsNumber;
string testNumber = pv;
foreach (string s in removableNumericCharacters)
testNumber = testNumber.Replace(s, string.Empty);
bool paramValueIsNumber = double.TryParse(testNumber, out paramValueAsNumber);
if (!(exactFlag) && !(pv.Contains("%")))
pv = String.Format("%{0}%", pv);
if (firstWord)
firstWord = false;
else
sb.Append("and");
if (negativeFlag)
sb.Append(" not");
sb.Append("(");
bool hasTests = false;
DbParameter originalParameter = null;
if (String.IsNullOrEmpty(quickFindHint) || !(quickFindHint.StartsWith(";")))
foreach (DataField tf in page.Fields)
if ((tf.AllowQBE && String.IsNullOrEmpty(tf.AliasName)) && (!((tf.IsPrimaryKey && tf.Hidden)) && (!(tf.Type.StartsWith("Date")) || paramValueIsDate)))
{
hasTests = true;
if ((parameter == null) || command.GetType().FullName.Contains("ManagedDataAccess"))
{
parameter = command.CreateParameter();
parameter.ParameterName = String.Format("{0}p{1}", _parameterMarker, command.Parameters.Count);
parameter.DbType = DbType.String;
command.Parameters.Add(parameter);
parameter.Value = pv;
示例14: CacheCommandProperties
protected virtual void CacheCommandProperties(DbCommand command) {
var oracleDbCommandType = command.GetType().GetTypeInfo();
ReflectionCache.PropBindByName = oracleDbCommandType.GetDeclaredProperty("BindByName");
ReflectionCache.PropArrayBindCount = oracleDbCommandType.GetDeclaredProperty("ArrayBindCount");
}