Ejemplo n.º 1
0
        private string GetSqlUpdateField(TSQL _tsql, ref MySqlCommand _sqlCommand)
        {
            string _return = "";

            for (int _index = 0; _index < _tsql.Fields.Count; _index++)
            {
                Field _field = _tsql.Fields[_index];
                _return += (_index > 0 ? "," : "");

                if (_field.AsName != "_ThisIsCustomField_")
                {
                    _return += " `" + _field.Name.Replace(".", "`.`") + "` =@" + _field.Name.Replace(".", "_");
                    if (_field.DbType == SqlDbType.Variant)
                    {
                        _sqlCommand.Parameters.AddWithValue("@" + _field.Name.Replace(".", "_"), _field.Value);
                    }
                    else
                    {
                        MySqlParameter _sqlParameter = _sqlCommand.Parameters.AddWithValue("@" + _field.Name.Replace(".", "_"), _field.DbType);
                        _sqlParameter.Value = _field.Value;
                    }
                }
                else
                {
                    _return += _field.Name;
                }
            }
            return(_return);
        }
Ejemplo n.º 2
0
        private string GetSqlTable(TSQL _tsql, ref MySqlCommand _sqlCommand)
        {
            string _return = "";

            if (_tsql.Type == TSQLType.Select)
            {
                for (int _index = 0; _index < _tsql.Tables.Count; _index++)
                {
                    Table _table = _tsql.Tables[_index];
                    if (_index > 0)
                    {
                        switch (_table.Relation)
                        {
                        case TableRelation.Inner:
                            _return += " INNER JOIN ";
                            _return += GetSqlTableNameString(_table) + " ON " + GetSqlWhere(_table.Conditions, ref _sqlCommand);
                            break;

                        case TableRelation.LeftOuter:
                            _return += " LEFT OUTER JOIN ";
                            _return += GetSqlTableNameString(_table) + " ON " + GetSqlWhere(_table.Conditions, ref _sqlCommand);
                            break;

                        case TableRelation.RightOuter:
                            _return += " RIGHT OUTER JOIN ";
                            _return += GetSqlTableNameString(_table) + " ON " + GetSqlWhere(_table.Conditions, ref _sqlCommand);
                            break;

                        case TableRelation.FullOuter:
                            throw new Exception("暂不支持FULL JOIN!");

                        // _return += " LEFT OUTER JOIN ";
                        // _return += GetSqlTableNameString(_table) + " ON " + GetSqlWhere(_table.Conditions, ref _sqlCommand);
                        //_return += " UNION ";
                        // _return +=  "SELECT ";
                        // _return +=  (this.Fields.Count > 0 ? GetSqlSelectField(this) : "*") + " FROM " + GetSqlTableNameString(_tsql.Tables[0]);
                        // _return += " RIGHT OUTER JOIN ";
                        // _return += GetSqlTableNameString(_table) + " ON " + GetSqlWhere(_table.Conditions, ref _sqlCommand);
                        //break;
                        case TableRelation.Cross:
                            _return += " CROSS JOIN ";
                            _return += GetSqlTableNameString(_table);
                            break;
                        }
                    }
                    else
                    {
                        _return += GetSqlTableNameString(_table);
                    }
                }
            }
            else
            {
                Table _table = _tsql.Tables[0];
                _return += "`" + _table.Name.Replace(".", "`.`") + "`";
            }
            return(_return);
        }
Ejemplo n.º 3
0
        private string GetSqlInsertField(TSQL _tsql)
        {
            string _return = "";

            for (int _index = 0; _index < _tsql.Fields.Count; _index++)
            {
                Field _field = _tsql.Fields[_index];
                _return += (_index > 0 ? "," : "");
                _return += "`" + _field.Name.Replace(".", "`.`") + "`";
            }
            return(_return);
        }
Ejemplo n.º 4
0
        private string GetSqlInsertValue(TSQL _tsql, ref MySqlCommand _sqlCommand)
        {
            string _return = "";

            for (int _index = 0; _index < _tsql.Fields.Count; _index++)
            {
                Field _field = _tsql.Fields[_index];
                _return += (_index > 0 ? "," : "");
                _return += "@" + _field.Name.Replace(".", "_");
                _sqlCommand.Parameters.AddWithValue("@" + _field.Name.Replace(".", "_"), _field.Value);
            }
            return(_return);
        }
Ejemplo n.º 5
0
        private string GetSqlSelectField(TSQL _tsql)
        {
            string _return = "";

            for (int _index = 0; _index < _tsql.Fields.Count; _index++)
            {
                Field _field = _tsql.Fields[_index];
                _return += (_index > 0 ? "," : "");
                if (_field.AsName != "_ThisIsCustomField_")
                {
                    _return += "`" + _field.Name.Replace(".", "`.`") + "`" + (_field.AsName != "" ? " AS [" + _field.AsName + "`" : "");
                }
                else
                {
                    _return += _field.Name;
                }
            }
            return(_return);
        }
Ejemplo n.º 6
0
        private string GetSqlOutput(TSQL _tsql)
        {
            if (_tsql.Outputs.Count == 0)
            {
                return("");
            }

            string _output = ";";

            for (int i = 0; i < _tsql.Outputs.Count; i++)
            {
                _output += i == 0 ? " " : ",";
                switch (_tsql.Outputs[i].Type)
                {
                case OutputType.Inserted: _output += " SELECT @@IDENTITY;"; break;

                case OutputType.Deleted: throw new Exception("删除不需要添加OutPut参数");    // _output += " OUTPUT DELETED."; break;
                }
                //    _output += "`" + _tsql.Outputs[i].Name + "`";
            }
            return(_output);
        }
Ejemplo n.º 7
0
        private string GetSqlGroupBy(TSQL _tsql)
        {
            string _return = "";

            for (int _index = 0; _index < _tsql.Groups.Count; _index++)
            {
                if (_index > 0)
                {
                    _return += ",";
                }
                switch (_tsql.Groups[_index].GroupType)
                {
                case GroupType.Field:
                    _return += "`" + _tsql.Groups[_index].FieldName.Replace(".", "`.`") + "`";
                    break;

                case GroupType.Value:
                    _return += _tsql.Groups[_index].FieldName;
                    break;
                }
            }
            return(_return);
        }
Ejemplo n.º 8
0
 private string GetSqlHaving(TSQL _tsql, ref MySqlCommand _sqlCommand)
 {
     return(GetSqlWhere(_tsql.Havings, ref _sqlCommand));
 }