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
28 using System.Collections.Generic;
\r
32 using DbLinq.Data.Linq.Sql;
\r
34 using DbLinq.Vendor.Implementation;
\r
36 namespace DbLinq.Firebird
\r
41 class FirebirdSqlProvider : SqlProvider
\r
43 public override string GetParameterName(string nameBase)
\r
45 return "@" + nameBase;
\r
48 protected override SqlStatement GetLiteralCount(SqlStatement a)
\r
53 protected override SqlStatement GetLiteralStringConcat(SqlStatement a, SqlStatement b)
\r
55 return SqlStatement.Format("CONCAT({0}, {1})", a, b);
\r
58 protected override char SafeNameStartQuote { get { return ' '; } }
\r
59 protected override char SafeNameEndQuote { get { return ' '; } }
\r
62 /// MySQL is case insensitive, and names always specify a case (there is no default casing)
\r
63 /// However, tables appear to be full lowercase
\r
65 /// <param name="dbName"></param>
\r
66 /// <returns></returns>
\r
67 protected override bool IsNameCaseSafe(string dbName)
\r
69 return dbName == dbName.ToUpperInvariant();
\r
73 /// Returns a table alias
\r
75 /// <param name="table"></param>
\r
76 /// <returns></returns>
\r
77 public override string GetTable(string table)
\r
79 var parts = table.Split('.');
\r
80 return GetSafeName(parts[parts.Length - 1]);
\r
84 /// Returns a LIMIT clause around a SELECT clause
\r
86 /// <param name="select">SELECT clause</param>
\r
87 /// <param name="limit">limit value (number of columns to be returned)</param>
\r
88 /// <returns></returns>
\r
89 public override SqlStatement GetLiteralLimit(SqlStatement select, SqlStatement limit)
\r
91 string stmt = limit.Count == 2
\r
92 ? string.Format("SELECT FIRST {0}, LAST {1}", limit[0].Sql, limit[1].Sql)
\r
93 : string.Format("SELECT FIRST {0}", limit[0].Sql);
\r
94 return select.Replace("SELECT", stmt, true);
\r
97 public override SqlStatement GetInsertIds(IList<SqlStatement> outputParameters, IList<SqlStatement> outputExpressions)
\r
99 // no parameters? no need to get them back
\r
100 if (outputParameters.Count == 0)
\r
102 // otherwise we keep track of the new values
\r
103 return SqlStatement.Format("SELECT {0} INTO {1} FROM DUAL",
\r
104 SqlStatement.Join(", ", (from outputExpression in outputExpressions select outputExpression.Replace(".NextVal", ".CurrVal", true)).ToArray()),
\r
105 SqlStatement.Join(", ", outputParameters.ToArray()));
\r