Ejemplo n.º 1
0
        private void BuildInsertQuery(string tableName)
        {
            byte i = 0;

            string[] columns    = new string[Columns.Keys.Count];
            string[] parameters = new string[Columns.Values.Count];

            Columns.Keys.CopyTo(columns, 0);

            foreach (string parameter in Columns.Values)
            {
                parameters[i] = parameter;
                i++;
            }
            if (columns.Length != 0)
            {
                Append(EnableTableAndColumnEncapsulation ? "INSERT INTO [{0}] ({1}) VALUES ({2})" : "INSERT INTO {0} ({1}) VALUES ({2})",
                       string.IsNullOrEmpty(tableName) ? TableName : tableName,
                       QueryUtility.GetQueryFragment(EnableTableAndColumnEncapsulation ? QueryFormat.DelimitedSquareBracket : QueryFormat.Delimited, columns),
                       QueryUtility.GetQueryFragment(QueryFormat.Delimited, parameters));
            }
            else
            {
                Append(EnableTableAndColumnEncapsulation ? "INSERT INTO [{0}] DEFAULT VALUES" : "INSERT INTO {0} DEFAULT VALUES",
                       string.IsNullOrEmpty(tableName) ? TableName : tableName);
            }
        }
Ejemplo n.º 2
0
        private void BuildSelectQuery(string tableName)
        {
            bool enableSquareBracketEncapsulationOnTable = EnableTableAndColumnEncapsulation;

            string[] columns = new string[KeyColumns.Count + Columns.Count];
            KeyColumns.Keys.CopyTo(columns, 0);
            Columns.Keys.CopyTo(columns, KeyColumns.Count);

            Append("SELECT ");
            if (EnableReadLimit)
            {
                Append("TOP {0} ", ReadLimit);
            }
            Append(QueryUtility.GetQueryFragment(EnableTableAndColumnEncapsulation ? QueryFormat.DelimitedSquareBracket : QueryFormat.Delimited, columns, true));
            if (enableSquareBracketEncapsulationOnTable)
            {
                enableSquareBracketEncapsulationOnTable = !(tableName.Contains("[") && tableName.Contains("]")); // check if we have an overriden tableName with square brackets already integrated and reverse the boolean result.
            }
            Append(enableSquareBracketEncapsulationOnTable ? " FROM [{0}]" : " FROM {0}", string.IsNullOrEmpty(tableName) ? TableName : tableName);
            if (EnableDirtyReads)
            {
                Append(" WITH(NOLOCK)");
            }
            AppendWhereClause();
        }