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
27 using System.Collections.Generic;
\r
31 using System.Data.Linq.Sql;
\r
33 using DbLinq.Data.Linq.Sql;
\r
36 using DbLinq.Vendor.Implementation;
\r
39 namespace DbLinq.Firebird
\r
46 class FirebirdSqlProvider : SqlProvider
\r
48 public override string GetParameterName(string nameBase)
\r
50 return "@" + nameBase;
\r
53 protected override SqlStatement GetLiteralCount(SqlStatement a)
\r
58 protected override SqlStatement GetLiteralStringConcat(SqlStatement a, SqlStatement b)
\r
60 return SqlStatement.Format("CONCAT({0}, {1})", a, b);
\r
63 protected override char SafeNameStartQuote { get { return ' '; } }
\r
64 protected override char SafeNameEndQuote { get { return ' '; } }
\r
67 /// MySQL is case insensitive, and names always specify a case (there is no default casing)
\r
68 /// However, tables appear to be full lowercase
\r
70 /// <param name="dbName"></param>
\r
71 /// <returns></returns>
\r
72 protected override bool IsNameCaseSafe(string dbName)
\r
74 return dbName == dbName.ToUpperInvariant();
\r
78 /// Returns a table alias
\r
80 /// <param name="table"></param>
\r
81 /// <returns></returns>
\r
82 public override string GetTable(string table)
\r
84 var parts = table.Split('.');
\r
85 return GetSafeName(parts[parts.Length - 1]);
\r
89 /// Returns a LIMIT clause around a SELECT clause
\r
91 /// <param name="select">SELECT clause</param>
\r
92 /// <param name="limit">limit value (number of columns to be returned)</param>
\r
93 /// <returns></returns>
\r
94 public override SqlStatement GetLiteralLimit(SqlStatement select, SqlStatement limit)
\r
96 string stmt = limit.Count == 2
\r
97 ? string.Format("SELECT FIRST {0}, LAST {1}", limit[0].Sql, limit[1].Sql)
\r
98 : string.Format("SELECT FIRST {0}", limit[0].Sql);
\r
99 return select.Replace("SELECT", stmt, true);
\r
102 public override SqlStatement GetInsertIds(IList<SqlStatement> outputParameters, IList<SqlStatement> outputExpressions)
\r
104 // no parameters? no need to get them back
\r
105 if (outputParameters.Count == 0)
\r
107 // otherwise we keep track of the new values
\r
108 return SqlStatement.Format("SELECT {0} INTO {1} FROM DUAL",
\r
109 SqlStatement.Join(", ", (from outputExpression in outputExpressions select outputExpression.Replace(".NextVal", ".CurrVal", true)).ToArray()),
\r
110 SqlStatement.Join(", ", outputParameters.ToArray()));
\r