Пример #1
0
func analyzeFrom(tableExprs sqlparser.TableExprs) (tablename string, hasHints bool) {
	if len(tableExprs) > 1 {
		return "", false
	}
	node, ok := tableExprs[0].(*sqlparser.AliasedTableExpr)
	if !ok {
		return "", false
	}
	return sqlparser.GetTableName(node.Expr), node.Hints != nil
}
Пример #2
0
func analyzeDelete(del *sqlparser.Delete, args []string, user *client.Client) (plan *ExecPlan, err error) {
	// Default plan
	plan = &ExecPlan{
		PlanId:    PLAN_PASS_DML,
		FullQuery: GenerateFullQuery(del),
	}

	tableName := sqlparser.GetTableName(del.Table)
	if tableName == "" {
		plan.Reason = REASON_TABLE
		return plan, nil
	}

	plan.Core = NewDeleteDML(del, tableName, args, user)

	return plan, nil
}
Пример #3
0
func analyzeInsert(ins *sqlparser.Insert, args []string, user *client.Client) (plan *ExecPlan, err error) {

	plan = &ExecPlan{
		PlanId:    PLAN_PASS_DML,
		FullQuery: GenerateFullQuery(ins),
	}
	tableName := sqlparser.GetTableName(ins.Table)

	if tableName == "" {
		plan.Reason = REASON_TABLE
		return plan, nil
	}

	plan.Core = NewInsertDML(ins, tableName, args, user)

	return plan, nil
}
Пример #4
0
func analyzeUpdate(upd *sqlparser.Update, args []string, user *client.Client) (plan *ExecPlan, err error) {
	// Default plan
	plan = &ExecPlan{
		PlanId:    PLAN_PASS_DML,
		FullQuery: GenerateFullQuery(upd),
	}

	tableName := sqlparser.GetTableName(upd.Table)
	if tableName == "" {
		plan.Reason = REASON_TABLE
		return plan, nil
	}

	plan.Core = NewUpdateDML(upd, tableName, args, user)

	/*
		conditions := analyzeWhere(upd.Where)
		if conditions == nil {
			plan.Reason = REASON_WHERE
			return plan, nil
		}*/

	return plan, nil
}