private void AddToHistory(SQLPart sql, ParameterStoreCollection parameters) { QueryStore q = new QueryStore(sql.SQL, parameters); string dir = System.IO.Path.GetDirectoryName(_historyPath); Directory.CreateDirectory(dir); using (StreamWriter wr = new StreamWriter(_historyPath, true, Encoding.UTF8)) { q.WriteToStream(wr); } }
public override SQLParts SplitSQL(string sql) { List <SQLPart> l = new List <SQLPart>(); TokenizedSQL tsql = new TokenizedSQL(sql); int i = 0; int n = tsql.Tokens.Length; while (i < n) { //Token t = tsql.Tokens[i]; for (; i < n; i++) { Token t = tsql.Tokens[i]; if (t.Kind != TokenKind.Space && t.Kind != TokenKind.NewLine && t.Kind != TokenKind.Comment) { break; } } int i0 = i; Token t0 = tsql.Tokens[i0]; bool endByNewLine = false; if (t0.Kind == TokenKind.Identifier && (string.Compare(t0.Value, "begin") == 0 || string.Compare(t0.Value, "start") == 0)) { endByNewLine = true; } for (; i < n && tsql.Tokens[i].Kind != TokenKind.Semicolon && (!endByNewLine || tsql.Tokens[i].Kind != TokenKind.NewLine); i++) { ; } string s = tsql.Extract(t0, tsql.Tokens[i - 1]); SQLPart sp = new SQLPart() { Offset = t0.Start.Index, SQL = s, ParameterNames = GetParameterNames(s).ToArray(), }; l.Add(sp); i++; } return(new SQLParts() { Items = l.ToArray(), ParameterNames = GetParameterNames(sql).ToArray() }); }
private void Add(SQLPart part, string clause) { switch (part) { case SQLPart.DECLARE: _queryParts[part] = Environment.NewLine + "DECLARE " + clause; break; case SQLPart.SET: _queryParts[part] = clause; break; case SQLPart.SELECT: _queryParts[part] = Environment.NewLine + "SELECT " + clause; break; case SQLPart.INTO: _queryParts[part] = Environment.NewLine + "INTO " + clause; break; case SQLPart.FROM: _queryParts[part] = Environment.NewLine + "FROM " + clause; break; case SQLPart.WHERE: _queryParts[part] = Environment.NewLine + "WHERE " + clause; break; case SQLPart.GROUPBY: _queryParts[part] = Environment.NewLine + "GROUP BY " + clause; break; case SQLPart.HAVING: _queryParts[part] = Environment.NewLine + "HAVING " + clause; break; case SQLPart.ORDERBY: _queryParts[part] = Environment.NewLine + "ORDER BY " + clause; break; case SQLPart.SEQUENCE: _queryParts[part] = Environment.NewLine + "CREATE SEQUENCE " + clause; break; case SQLPart.TRIGGER: _queryParts[part] = Environment.NewLine + "CREATE OR REPLACE TRIGGER " + clause; break; case SQLPart.DELETE: _queryParts[part] = Environment.NewLine + "DELETE TABLE " + clause; break; case SQLPart.CREATE: _queryParts[part] = Environment.NewLine + "CREATE TABLE " + _tableName + " (" + clause + ")"; break; case SQLPart.UPDATE: _queryParts[part] = Environment.NewLine + "UPDATE TABLE " + clause; break; } }
private void Add(SQLPart part, string clause) { switch (part) { case SQLPart.DECLARE: _queryParts[part] = Environment.NewLine + "DECLARE " + clause; break; case SQLPart.SET: _queryParts[part] = clause; break; case SQLPart.SELECT: _queryParts[part] = Environment.NewLine + "SELECT " + clause; break; case SQLPart.INTO: _queryParts[part] = Environment.NewLine + "INTO " + clause; break; case SQLPart.FROM: _queryParts[part] = Environment.NewLine + "FROM " + clause; break; case SQLPart.WHERE: _queryParts[part] = Environment.NewLine + "WHERE " + clause; break; case SQLPart.GROUPBY: _queryParts[part] = Environment.NewLine + "GROUP BY " + clause; break; case SQLPart.HAVING: _queryParts[part] = Environment.NewLine + "HAVING " + clause; break; case SQLPart.ORDERBY: _queryParts[part] = Environment.NewLine + "ORDER BY " + clause; break; case SQLPart.SEQUENCE: _queryParts[part] = Environment.NewLine + "CREATE SEQUENCE " + clause; break; case SQLPart.TRIGGER: _queryParts[part] = Environment.NewLine + "CREATE OR REPLACE TRIGGER " + clause; break; case SQLPart.DELETE: _queryParts[part] = Environment.NewLine + "DELETE TABLE " + clause; break; case SQLPart.CREATE: _queryParts[part] = Environment.NewLine + "CREATE TABLE " + _tableName + " (" + clause + ")"; break; case SQLPart.UPDATE: _queryParts[part] = Environment.NewLine + "UPDATE TABLE " + clause; break; } }
/// <summary> /// 处理字段内容 /// </summary> /// <param name="blank"></param> /// <param name="field"></param> /// <param name="comments"></param> /// <returns></returns> private string GetFieldInfoSelect(string blank, string field, string comments, SQLPart sqlPart) { string rowInfo = string.Empty; if (sqlPart == SQLPart.Body) { if (!string.IsNullOrEmpty(comments)) { rowInfo = blank + field.ToLower() + ", --" + comments; } else { rowInfo = blank + field.ToLower() + ", "; } } else if (sqlPart == SQLPart.Head) { if (!string.IsNullOrEmpty(comments)) { rowInfo = "select " + field.ToLower() + ", --" + comments; } else { rowInfo = "select " + field.ToLower() + ", "; } } else { if (!string.IsNullOrEmpty(comments)) { rowInfo = blank + field.ToLower() + " --" + comments; } else { rowInfo = blank + field.ToLower() + " "; } } return(rowInfo + "\n"); }
public static SQLPart create(SQLPartType type, string partValue) { SQLPart i = new SQLPart(); i.value = partValue; i.partType = type; return i; }
public void addPart(string addItem, SQLPartType addPartType) { SQLPart sp = this.sParts.Find(delegate(SQLPart opart) { return (opart.partType == addPartType); }); if (sp == null) { sp = new SQLPart(); sp.partType = addPartType; sParts.Add(sp); } if (sp.value == null || sp.value == "") { sp.value += SQLPartKeyword(addPartType).startkeyword; } else if (addPartType == SQLPartType.where) { if (sp.value != null && sp.value.Trim() != "" && sp.value.Trim().ToUpper() != "WHERE") { sp.value += " and "; // +addItem; } } else if (addPartType == SQLPartType.fields) { sp.value += ", "; } if (addPartType == SQLPartType.where && !(String.IsNullOrEmpty(addItem))) { sp.value += "(" + addItem + ")"; } else { sp.value += addItem; } }