public static bool TableExists(MySqlConnection conn, string name) { bool exists = false; QuerySql(conn, "SHOW TABLES LIKE @name", reader => { exists = reader.HasRows; }, ("@name", name)); return(exists); }
/// <summary> /// 给所有用到的表加上 and table.delete_at is null /// </summary> /// <returns></returns> public SqlBuilderMultiple DeleteAtIsNull() { foreach (var item in Tables) { QuerySql.Append($" and [{item}].delete_at is null "); } return(this); }
/// <summary> /// and tableName.columnName is not null /// </summary> /// <param name="tableName"></param> /// <param name="columnName"></param> /// <param name="value"></param> /// <returns></returns> public SqlBuilderMultiple NotNull(string tableName, string columnName, bool value) { if (!value) { return(this); } QuerySql.Append($" and [{tableName}].[{columnName}] is not null "); return(this); }
/// <summary> /// and tableName.columnName != value /// </summary> /// <param name="tableName"></param> /// <param name="columnName"></param> /// <param name="value"></param> /// <returns></returns> public SqlBuilderMultiple ForceNotEquals(string tableName, string columnName, long value) { long temp = Number; QuerySql.Append($" and [{tableName}].[{columnName}]<> @{tableName}_{columnName}{temp} "); Parameters.Add($"{tableName}_{columnName}{temp}", value); return(this); }
/// <summary> /// group by /// </summary> /// <param name="table"></param> /// <param name="cloumn"></param> /// <param name="groupBy"></param> /// <returns></returns> public SqlBuilderMultiple GroupBy(string table, string cloumn, bool groupBy = true) { if (FirstGroupBy) { FirstGroupBy = false; QuerySql.Append($" group by [{table}].[{cloumn}]"); return(this); } QuerySql.Append($", [{table}].[{cloumn}]"); return(this); }
/// <summary> /// and tableName.columnName like "%value%" /// </summary> /// <param name="tableName"></param> /// <param name="columnName"></param> /// <param name="value"></param> /// <returns></returns> public SqlBuilderMultiple Like(string tableName, string columnName, string value) { if (string.IsNullOrEmpty(value)) { return(this); } long temp = Number; QuerySql.Append($" and [{tableName}].[{columnName}] like @{tableName}_{columnName}{temp} "); Parameters.Add($"{tableName}_{columnName}{temp}", $"%{value}%"); return(this); }
/// <summary> /// and tableName.columnName <![CDATA[<>]]> value (Optional) /// </summary> /// <param name="tableName"></param> /// <param name="columnName"></param> /// <param name="value"></param> /// <returns></returns> public SqlBuilderMultiple NotEquals(string tableName, string columnName, int?value) { if (value == null || value == 0) { return(this); } long temp = Number; QuerySql.Append($" and [{tableName}].[{columnName}] <> @{tableName}_{columnName}{temp} "); Parameters.Add($"{tableName}_{columnName}{temp}", value); return(this); }
/// <summary> /// and tableName.columnName in (values[1],values[2]) /// </summary> /// <param name="tableName"></param> /// <param name="columnName"></param> /// <param name="values"></param> /// <returns></returns> public SqlBuilderMultiple NotIn <T>(string tableName, string columnName, IList <T> values) { if (values == null) { return(this); } long temp = Number; QuerySql.Append($" and [{tableName}].[{columnName}] not in (@{tableName}_{columnName}{temp})"); Parameters.Add($"{tableName}_{columnName}{temp}", values); return(this); }
///// <param name='operations'> ///// Reference to the DocumentDBRestAPIClient.IDocumentDbConnector. ///// </param> ///// <param name='ridOffer'> ///// Required. The Offer Id ///// </param> ///// <param name='authorization'> ///// Required. The authentication type and signature token. Both master ///// key and resource tokens are allowed for operation. example: ///// <c>type={typeoftoken}%26ver={tokenversion}%26sig={hashsignature}</c> ///// </param> ///// <param name='contentType'> ///// Required. Optional. For creating a database, the Content-Type ///// header must be application/json. ///// </param> ///// <param name='userAgent'> ///// Required. Optional. The string of client user agent performing the ///// request. The recommended format is ///// <c>{ user agentname}/{ version}</c> ///// </param> ///// <param name='xMSDate'> ///// Required. The date of the request The date is expressed in ///// Coordinated Universal Time format. example: ///// <example> ///// Fri, 08 Apr ///// 2015 03:52:31 GMT ///// </example> ///// </param> ///// <param name='xMSVersion'> ///// Required. The version of DocumentDB REST service. The latest ///// version is used when the header is not provided use 2015-08-06 ///// </param> ///// <param name='cancellationToken'> ///// Cancellation token. ///// </param> //public static async Task<Offer> GetOfferAsync(IDocumentDbConnector operations, string ridOffer, // string authorization, string contentType, string userAgent, string xMSDate, string xMSVersion, // CancellationToken cancellationToken = default(CancellationToken)) //{ // var result = // await // operations.GetOfferWithOperationResponseAsync(ridOffer, authorization, contentType, userAgent, // xMSDate, xMSVersion, cancellationToken).ConfigureAwait(false); // return result.Body; //} /// <param name='operations'> /// Reference to the DocumentDBRestAPIClient.IDocumentDbConnector. /// </param> /// <param name='databaseaccount'> /// Required. The Database Account Name /// </param> /// <param name='request'> /// Required. /// </param> /// <param name='authorization'> /// Required. The authentication type and signature token. Both master /// key and resource tokens are allowed for operation. example: /// <c>type={typeoftoken}%26ver={tokenversion}%26sig={hashsignature}</c> /// </param> /// <param name='userAgent'> /// Required. Optional. The string of client user agent performing the /// request. The recommended format is /// <c>{ user agentname}/{ version}</c> /// </param> /// <param name='xMSDate'> /// Required. The date of the request The date is expressed in /// Coordinated Universal Time format. example: /// <example> /// Fri, 08 Apr /// 2015 03:52:31 GMT /// </example> /// </param> /// <param name='xMSVersion'> /// Required. The version of DocumentDB REST service. The latest /// version is used when the header is not provided use 2015-08-06 /// </param> /// <param name='contentType'> /// Required. Required. The Content-Type header must be /// application/json. /// </param> /// <param name='xMSDocumentdbQueryEnableScan'> /// Required. /// </param> /// <param name='xMSDocumentdbIsquery'> /// Required. /// </param> public static QueryResponseBody QueryOffer(IDocumentDbConnector operations, string databaseaccount, QuerySql request, string authorization, string userAgent, string xMSDate, string xMSVersion, string contentType, bool xMSDocumentdbQueryEnableScan, bool xMSDocumentdbIsquery) { return (Task.Factory.StartNew( s => ((IDocumentDbConnector)s).QueryOfferAsync(databaseaccount, request, authorization, userAgent, xMSDate, xMSVersion, contentType, xMSDocumentdbQueryEnableScan, xMSDocumentdbIsquery), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default) .Unwrap() .GetAwaiter() .GetResult()); }
/// <summary> /// 精确到时分秒进行查询 /// </summary> /// <param name="tableName"></param> /// <param name="columnName"></param> /// <param name="beginValue"></param> /// <param name="endValue"></param> /// <returns></returns> public SqlBuilderMultiple BetweenDateByAccurate(string tableName, string columnName, DateTime?beginValue, DateTime?endValue) { if (beginValue == null || endValue == null) { return(this); } long temp1 = Number, temp2 = Number; QuerySql.Append($" and [{tableName}].[{columnName}] between @{tableName}_{columnName}{temp1} and @{tableName}_{columnName}{temp2} "); Parameters.Add($"{tableName}_{columnName}{temp1}", beginValue); Parameters.Add($"{tableName}_{columnName}{temp2}", endValue); return(this); }
/// <summary> /// 小于 /// </summary> /// <param name="tableName"></param> /// <param name="columnName"></param> /// <param name="value"></param> /// <returns></returns> public SqlBuilderMultiple Less(string tableName, string columnName, DateTime?value) { if (value == null) { return(this); } long temp = Number; QuerySql.Append($" and [{tableName}].[{columnName}] < @{tableName}_{columnName}{temp} "); Parameters.Add($"{tableName}_{columnName}{temp}", value); return(this); }
/// <summary> /// and (sql) between value and value2 /// </summary> /// <param name="sql"></param> /// <param name="beginValue"></param> /// <param name="endValue"></param> /// <returns></returns> public SqlBuilderMultiple Between(string sql, int?beginValue, int?endValue) { if (beginValue == null || endValue == null) { return(this); } long temp1 = Number, temp2 = Number; QuerySql.Append($" and ({sql}) between @{temp1} and @{temp2} "); Parameters.Add($"{temp1}", beginValue); Parameters.Add($"{temp2}", endValue); return(this); }
/// <summary> /// and tableName.columnName in (values[1],values[2]) /// </summary> /// <param name="tableName"></param> /// <param name="columnName"></param> /// <param name="values"></param> /// <returns></returns> public SqlBuilderMultiple In(string tableName, string columnName, IList <string> values) { if (values == null) { return(this); } if (!values.Any()) { QuerySql.Append($" and 1 != 1"); return(this); } long temp = Number; QuerySql.Append($" and [{tableName}].[{columnName}] in (@{tableName}_{columnName}{temp})"); Parameters.Add($"{tableName}_{columnName}{temp}", values); return(this); }
/// <summary> /// and (columnNames[0] like "%value%" or columnNames[1] like "%value%" ) /// </summary> /// <param name="columnNames"></param> /// <param name="value"></param> /// <returns></returns> public SqlBuilderMultiple LikeOr(IList <string> columnNames, string value) { if (string.IsNullOrEmpty(value) || columnNames == null || !columnNames.Any()) { return(this); } var stringBuilder = new StringBuilder(); QuerySql.Append(" and ("); foreach (var item in columnNames) { var temp = Number; stringBuilder.Append($" or {item} like @{item}{temp} "); Parameters.Add($"{item}{temp}", $"%{value}%"); } QuerySql.Append(stringBuilder.ToString().TrimStart(" or".ToCharArray())); QuerySql.Append(" ) "); return(this); }
/// <summary> /// and ( tableName.columnName = value1 or tableName.columnName = value2) /// </summary> /// <param name="tableName"></param> /// <param name="columnName"></param> /// <param name="values"></param> /// <returns></returns> public SqlBuilderMultiple EqualsOr(string tableName, string columnName, IList <string> values) { if (values == null) { return(this); } if (!values.Any()) { QuerySql.Append(" and 1 != 1"); return(this); } var stringBuilder = new StringBuilder(); QuerySql.Append(" and ("); foreach (var value in values) { var temp = Number; stringBuilder.Append($" or [{tableName}].[{columnName}] = @{tableName}_{columnName}{temp}"); Parameters.Add($"{tableName}_{columnName}{temp}", value); } QuerySql.Append(stringBuilder.ToString().TrimStart(" or".ToCharArray())); QuerySql.Append(") "); return(this); }
/// <summary> /// 得到时间的where语句 /// </summary> /// <returns></returns> public string GetTimeWhere(string strTime) { Hashtable ht = new Hashtable(); ht.Add("TimeType", 0); ht.Add("Time", strTime); string strViewType = Dainfo.strView; string strtimeW = "1=1"; switch (strViewType) { case "大气监测": case "降水监测": QuerySql timewhere = new QuerySql(); strtimeW = timewhere.QueryTimeSql(ht); break; case "降尘监测": case "三年行动降尘": QuerySql timewhere8 = new QuerySql(); strtimeW = timewhere8.QueryEQIAR_RD_TimeSql(ht); break; case "区域噪声": case "功能区噪声": case "道路交通噪声": case "鸣号监测": EQINTQuerySql timewhere1 = new EQINTQuerySql(); strtimeW = timewhere1.QueryTimeSql(ht); break; case "河流监测": case "饮用水监测": case "湖库监测": case "海水监测": EQIWRQuerySql timewhere2 = new EQIWRQuerySql(); strtimeW = timewhere2.QueryTimeSql(ht); break; case "企业污染源": EQIPQuerySql timewhere3 = new EQIPQuerySql(); strtimeW = timewhere3.QueryTimeSql(strTime, "企业污染源"); break; case "污水处理厂": EQIPQuerySql timewhere4 = new EQIPQuerySql(); strtimeW = timewhere4.QueryTimeSql(strTime, "污水处理厂"); break; case "固废处理厂": EQIPQuerySql timewhere5 = new EQIPQuerySql(); strtimeW = timewhere5.QueryTimeSql(strTime, "固废处理厂"); break; case "厂界噪声": EQIPQuerySql timewhere6 = new EQIPQuerySql(); strtimeW = timewhere6.QueryTimeSql(strTime, "厂界噪声"); break; case "土壤监测": EQISOQuerySql timewhere7 = new EQISOQuerySql(); strtimeW = timewhere7.QueryTimeSql(ht); break; } return(strtimeW); }
/// <summary> /// 用于补充不确定是否需要DeleteAtIsNull 的表,例如自定义语句 /// </summary> /// <param name="tableName"></param> /// <returns></returns> public SqlBuilderMultiple DeleteAtIsNull(string tableName) { QuerySql.Append($" and [{tableName}].delete_at is null "); return(this); }
/// <summary> /// 获得where后面的sql,并做了去 and 处理 /// </summary> /// <returns></returns> public override string ToString() { string queryString = QuerySql.ToString(); return(queryString.TrimStart(" and".ToCharArray())); }
public QuerySql <T, T, T> Load <T>(DbSqlCommand sqlCommand) { var querySql = new QuerySql <T, T, T>(this, sqlCommand); return(querySql); }
private void Page_Load(object sender, EventArgs e) { string url = null; string str2 = null; XmlDocument xdoc = null; try { string str8; QuerySql sql; SqlToTree tree; str2 = base.Request.Params["key"]; if ((str2 == null) || (str2.Length == 0)) { str2 = base.Request.QueryString.ToString(); } if (str2 == "HelloWorld") { base.Response.ContentType = ("text/html;charset=UTF-8"); base.Response.Write("HelloWorld"); return; } Logger.debug("后台 key=" + str2); if (str2 == "logger") { string src = new StreamReader(base.Request.InputStream).ReadToEnd(); Logger.debug("前台:" + Escape.unescape(src)); return; } this.initConfigFileEbiao(base.Request); ConnectionConfig.initConfigFile(base.Request, this.Session); string str4 = null; string dsName = base.Request.Params["datasourceName"]; ConnectionConfig connConfig = null; connConfig = new ConnectionConfig(dsName); if (str2 == "DbToFile") { new DbStru(connConfig, null, base.Request).DbToFile(base.Response); return; } bool flag = ((((str2 == "loadFileStream") || (str2 == "getTempImage")) || ((str2 == "saveasExcelAll") || (str2 == "saveasExcel"))) || (((str2 == "saveasPdf") || (str2 == "run")) || ((str2 == "calcStr") || (str2 == "importExcel")))) || (str2 == "genHtmlFile"); RunReport report = new RunReport(base.Request, this.Session, connConfig.getDBOperator()); switch (str2) { case "loadFileStream": report.loadFileStream(base.Request, base.Response); return; case "getTempImage": report.getTempImage(base.Request, base.Response); return; case "saveasExcelAll": report.saveasExcel(base.Request, base.Response, false); return; case "saveasExcel": report.saveasExcel(base.Request, base.Response, true); return; case "saveasPdf": report.saveasPdf(base.Request, base.Response); return; case "run": url = report.run(base.Request); break; case "calcStr": url = report.calcStr(base.Request); break; case "importExcel": { string sDest = base.Request["excelfile"]; sDest = PathTool.getRealPath(base.Request, FileAction.basePath + sDest); string str7 = base.Request["spath"]; url = ImportExcel.FileConvert(PathTool.getRealPath(base.Request, FileAction.basePath + str7), sDest); break; } case "genHtmlFile": Logger.debug("开始成批运算报表:"); url = report.genHtmlFile(base.Request); break; } if (flag) { goto Label_0BE9; } if (((((str2 != "setSession") && (str2 != "getSession")) && ((str2 != "uploadFile") && (str2 != "readImage"))) && ((str2 != "readClob") && (str2 != "saveFile"))) && (str2 != "zkLoadMod")) { str4 = new StreamReader(base.Request.InputStream).ReadToEnd(); Logger.debug("XML串: " + str4); if ((str2 != "saveRunInfo") && (str2 != "readDomainRes")) { xdoc = new XmlDocument(); xdoc.LoadXml(str4); } } if (str2 != "loadingBatchAction") { goto Label_05FE; } StringBuilder builder = new StringBuilder("<root>"); int num = 0; Label_041D: if (num >= xdoc.DocumentElement.ChildNodes.Count) { goto Label_05E9; } XmlDocument document2 = new XmlDocument(); document2.LoadXml(xdoc.DocumentElement.ChildNodes.Item(num).OuterXml); try { dsName = xdoc.DocumentElement.ChildNodes.Item(num).Attributes["datasourceName"].Value; } catch (Exception) { } goto Label_0573; Label_048C: builder.Append(sql.fillcombox()); goto Label_055B; Label_04A0: if (str8 == "getDsns") { builder.Append(connConfig.getDsns()); } else if (str8 == "fc_select") { builder.Append(sql.fc_select()); } else if (str8 == "dataset_fields1") { builder.Append(sql.dataset_fields1()); } else if (str8 == "dataset_select") { builder.Append(sql.dataset_select()); } else if (str8 == "sqltotreedata") { builder.Append(tree.sqltotreedata()); } else if (str8 == "getTreeXml") { builder.Append(tree.getTreeXml()); } Label_055B: builder.Append("</root>"); num++; goto Label_041D; Label_0573: str8 = xdoc.DocumentElement.ChildNodes.Item(num).Attributes["key"].Value; connConfig = new ConnectionConfig(dsName); sql = new QuerySql(connConfig, document2, base.Request, this.Session); tree = new SqlToTree(connConfig, document2); builder.Append("<root>"); if (str8 != "fillcombox") { goto Label_04A0; } goto Label_048C; Label_05E9: builder.Append("</root>"); url = builder.ToString(); Label_05FE: if (str2 == "getDsns") { url = connConfig.getDsns(); } if (str2 == "isRunForm") { url = PermitForm.isRunForm(base.Request, this.Session, connConfig.getDBOperator()); } if (str2 == "isRunReport") { url = PermitReport.isRunReport(base.Request, this.Session, connConfig.getDBOperator()); } EbiaoFile file = new EbiaoFile(connConfig.getDBOperator(), xdoc, base.Request); if (str2 == "saveFile") { url = file.saveFile(); } if (str2 == "loadFile") { url = file.loadFile(); } if (str2 == "ToInDs") { url = file.ToInDs(); } QuerySql sql2 = new QuerySql(connConfig, xdoc, base.Request, this.Session); if (str2 == "fillcombox") { url = sql2.fillcombox(); } if (str2 == "sqltoxml") { url = sql2.sqltoxml(); } if (str2 == "SqlToField") { url = sql2.SqlToField(); } if (str2 == "fc_select") { url = sql2.fc_select(); } if (str2 == "dataset_fields1") { url = sql2.dataset_fields1(); } if (str2 == "dataset_select") { url = sql2.dataset_select(); } if (str2 == "doUploadInfo") { url = sql2.doUploadInfo(); } if (str2 == "crosstab") { url = sql2.crosstab(); } ExportData data = new ExportData(xdoc, base.Request, this.Session); if (str2 == "exportData") { data.run(); } ImportData data2 = new ImportData(base.Request, this.Session, connConfig); if (str2 == "importData") { url = data2.run(); } WebDesign design = new WebDesign(connConfig, xdoc, base.Request); if (str2 == "designdjsave") { url = design.designdjsave(); } if (str2 == "loadClob") { url = design.loadClob(); } cn.com.fcsoft.ajax.PathFile file2 = new cn.com.fcsoft.ajax.PathFile(xdoc); if (str2 == "GetUrl") { url = file2.GetUrl(base.Request); } DbStru stru2 = new DbStru(connConfig, xdoc, base.Request); if (str2 == "GetAllTables") { url = stru2.GetAllTables(); } if (str2 == "GetFieldName") { url = stru2.GetFieldName(); } if (str2 == "setDbStru") { url = stru2.setDbStru(); } SubmitData data3 = new SubmitData(connConfig, xdoc, base.Request, this.Session); if (str2 == "doSaveData") { url = data3.doSaveData(); } FileAction action = new FileAction(xdoc, base.Request); if (str2 == "readdesignhtml") { url = action.readdesignhtml(); } if (str2 == "savedesignhtml") { url = action.savedesignhtml(); } if (str2 == "genDjHtmlFile") { url = action.genDjHtmlFile(); } if (str2 == "GetFileContent") { url = action.GetFileContent(); } if (str2 == "DelUploadFile") { url = action.DelUploadFile(); } if (str2 == "uploadFile") { url = action.uploadFile(); } if (str2 == "fileExist") { url = action.fileExist(); } MaxNo no = new MaxNo(connConfig, xdoc, this.Session); if (str2 == "getMaxIntNo") { url = no.getMaxIntNo(); } if (str2 == "getRecnum") { url = no.getRecnum(); } if (str2 == "getAutoNum") { url = no.getAutoNum(); } SqlToTree tree2 = new SqlToTree(connConfig, xdoc); if (str2 == "sqltotreedata") { url = tree2.sqltotreedata(); } if (str2 == "getTreeXml") { url = tree2.getTreeXml(); } DoSession session = new DoSession(base.Request, this.Session); if (str2 == "setSession") { url = session.setSession(); } if (str2 == "getSession") { url = session.getSession(); } cn.com.fcsoft.ajax.ImageField field = new cn.com.fcsoft.ajax.ImageField(connConfig, base.Request); if (str2 == "readImage") { field.readImage(base.Response); } if (str2 == "writeImage") { url = field.writeImage(); } ClobField field2 = new ClobField(connConfig, base.Request); if (str2 == "readClob") { url = field2.readClob(); } if (str2 == "writeClob") { url = field2.writeClob(); } EformRole role = new EformRole { session = this.Session, request = base.Request, xdoc = xdoc, oDb = connConfig.getDBOperator() }; if (str2 == "roleSet") { url = role.roleSet(); } if (str2 == "roleCheckEmployee") { url = role.roleCheckEmployee(); } if (str2 == "getAllPubParamValue") { url = role.getAllPubParamValue(); } if (str2 == "batchExecSql") { if (EformRole.getPubParamValue(this.Session, "用户.ID") != "systemadmin") { throw new Exception("只有用户 admin 才有权做此操作!"); } string str10 = xdoc.DocumentElement.ChildNodes.Item(0).InnerText; DBOperator @operator = null; IDbCommand command = null; IDbTransaction transaction = null; try { @operator = connConfig.getDBOperator(); @operator.Open(); command = @operator.Connection.CreateCommand(); command.Connection = (@operator.Connection); transaction = @operator.Connection.BeginTransaction(); command.Transaction = (transaction); command.CommandText = (str10); command.ExecuteNonQuery(); transaction.Commit(); command.Dispose(); @operator.Close(); } catch (Exception exception) { try { transaction.Rollback(); } catch (Exception) { } throw exception; } finally { try { @operator.Close(); } catch (Exception) { } } } } catch (Exception exception2) { Logger.error(exception2.StackTrace); url = JSON.errInfoToJson(exception2); } Label_0BE9: if ((url != null) || (str2 != "readImage")) { /* * Bill.aspx?key=run&spath=/rpt/s_simplelist.htm&tempfilepath=/tmp/file/&pageno=1&cacheid=&e_paramid= * ebrun.htm?name=s_simplelist */ base.Response.ContentType = ("text/html;charset=UTF-8"); File.WriteAllText(@"E:\DB\PlatForm\FlexCell.NET\ebiao\bin\cleaned\src\Web\" + str2 + "_test.htm", url); base.Response.Write(url); } }
public QuerySql <T, T, T> Load <T>(string sql, IReadOnlyList <object> values) { var querySql = new QuerySql <T, T, T>(this, sql, values); return(querySql); }
public QuerySql <T, T, T> Load <T>(string sql, params object[] values) { var querySql = new QuerySql <T, T, T>(this, sql, values); return(querySql); }