/// <summary> /// Must only update a single row at a time. Must have a where clause that specifies the primary key fields. Where clause can only use ANDed equal conditions (like chat_id=2 AND chat_type='X")"; /// </summary> /// <param name="database"></param> /// <param name="sql"></param> public UpdateStatement(IDatabase database, string sql) { this.Sql = sql; if (this.IsSqlTableName) { this.fromClause = this.Sql; this.setClause = null; this.whereClause = null; } else { // Confirm the sql is valid Match match = STATEMENT_REGEX.Match(this.Sql); if (!match.Success) { throw new Exception($"Invalid sql '{this.Sql}'"); } // Extract each clause this.fromClause = match.Groups[1].Value.Trim(); this.setClause = match.Groups[2].Value.Trim(); this.whereClause = match.Groups[3].Value.Trim(); } // Parse the FROM clause this.StatementFromRefs = StatementFromRef.ParseFromRefs(database, this.fromClause); }
/// <summary> /// /// </summary> /// <param name="database"></param> /// <param name="sql">Can be a table name or full SQL. Full SQL can use @@names and @@values tokens to retrieve values from the record parameter.</param> public InsertStatement(IDatabase database, string sql) { this.Sql = sql; //this.SetSql(sql, "INSERT INTO @@tableName (@@names) VALUES (@@values)"); if (this.IsSqlTableName) { this.fromClause = this.Sql; this.namesClause = null; this.valuesClause = null; } else { // Confirm the sql is valid Match match = STATEMENT_REGEX.Match(this.Sql); if (!match.Success) { throw new Exception($"Invalid sql '{this.Sql}'"); } // Extract each clause this.fromClause = match.Groups["fromClause"].Value.Trim(); this.namesClause = match.Groups["namesClause"].Value.Trim(); this.valuesClause = match.Groups["valuesClause"].Value.Trim(); } // Parse the FROM clause this.StatementFromRefs = StatementFromRef.ParseFromRefs(database, this.fromClause); }
protected void Compile(IDatabase database) { this.StatementFromRefs = StatementFromRef.ParseFromRefs(database, this.fromClause); }