5 // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
\r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
\r
8 // of this software and associated documentation files (the "Software"), to deal
\r
9 // in the Software without restriction, including without limitation the rights
\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
11 // copies of the Software, and to permit persons to whom the Software is
\r
12 // furnished to do so, subject to the following conditions:
\r
14 // The above copyright notice and this permission notice shall be included in
\r
15 // all copies or substantial portions of the Software.
\r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
29 using System.Collections.Generic;
\r
31 using DbLinq.Vendor.Implementation;
\r
33 using DbLinq.Data.Linq.Sql;
\r
34 using DbLinq.Data.Linq.Sugar.Expressions;
\r
37 namespace DbLinq.Firebird
\r
43 class FirebirdSqlProvider : SqlProvider
\r
45 public override ExpressionTranslator GetTranslator()
\r
47 return new FirebirdExpressionTranslator();
\r
50 public override string GetParameterName(string nameBase)
\r
52 return "@" + nameBase;
\r
55 protected override SqlStatement GetLiteralCount(SqlStatement a)
\r
60 protected override SqlStatement GetLiteralStringConcat(SqlStatement a, SqlStatement b)
\r
62 return SqlStatement.Format("{0} || {1}", a, b);
\r
65 protected override SqlStatement GetLiteralStringToLower(SqlStatement a)
\r
67 return string.Format("LOWER({0})", a);
\r
70 protected override SqlStatement GetLiteralStringToUpper(SqlStatement a)
\r
72 return string.Format("UPPER({0})", a);
\r
75 protected override char SafeNameStartQuote { get { return ' '; } }
\r
76 protected override char SafeNameEndQuote { get { return ' '; } }
\r
80 /// Returns a table alias
\r
82 /// <param name="table"></param>
\r
83 /// <returns></returns>
\r
84 public override string GetTable(string table)
\r
86 var parts = table.Split('.');
\r
87 return GetSafeName(parts[parts.Length - 1]);
\r
91 /// Returns a LIMIT clause around a SELECT clause
\r
93 /// <param name="select">SELECT clause</param>
\r
94 /// <param name="limit">limit value (number of columns to be returned)</param>
\r
95 /// <returns></returns>
\r
96 public override SqlStatement GetLiteralLimit(SqlStatement select, SqlStatement limit)
\r
98 string stmt = limit.Count == 2
\r
99 ? string.Format("SELECT FIRST {0}, LAST {1}", limit[0].Sql, limit[1].Sql)
\r
100 : string.Format("SELECT FIRST {0}", limit[0].Sql);
\r
101 return select.Replace("SELECT", stmt, true);
\r
104 public override SqlStatement GetLiteralLimit(SqlStatement select, SqlStatement limit, SqlStatement offset, SqlStatement offsetAndLimit)
\r
106 string stmt = (limit.Count == 2
\r
107 ? string.Format("SELECT FIRST {0}, LAST {1} SKIP {2}", limit[0].Sql, limit[1].Sql, offset)
\r
108 : string.Format("SELECT FIRST {0} SKIP {1}", limit[0].Sql, offset));
\r
109 //string stmt = string.Format("SELECT FIRST {0} SKIP {1}", limit, offset);
\r
111 return select.Replace("SELECT", stmt, true);
\r
115 public override SqlStatement GetInsertIds(SqlStatement table, IList<SqlStatement> autoPKColumn, IList<SqlStatement> inputPKColumns, IList<SqlStatement> inputPKValues, IList<SqlStatement> outputColumns, IList<SqlStatement> outputParameters, IList<SqlStatement> outputExpressions)
\r
117 // no parameters? no need to get them back
\r
118 if (outputParameters.Count == 0)
\r
120 // otherwise we keep track of the new values
\r
121 return SqlStatement.Format("SELECT {0} INTO {1} FROM DUAL",
\r
122 SqlStatement.Join(", ", (from outputExpression in outputExpressions select outputExpression.Replace(".NextVal", ".CurrVal", true)).ToArray()),
\r
123 SqlStatement.Join(", ", outputParameters.ToArray()));
\r