Added:
trunk/MySql.Data.Entity/Provider/Generators/FunctionFragment.cs
trunk/MySql.Data.Entity/Provider/Generators/FunctionProcessor.cs
Removed:
trunk/MySql.Data.Entity/Provider/Generators/FunctionProcessor
Modified:
trunk/MySql.Data.Entity/Provider/Generators/InsertGenerator.cs
trunk/MySql.Data.Entity/Provider/Generators/SelectGenerator.cs
trunk/MySql.Data.Entity/Provider/Generators/SqlGenerator.cs
trunk/MySql.Data.Entity/Provider/Generators/UpdateGenerator.cs
trunk/MySql.Data.Entity/Provider/MySql.Data.Entity.csproj
trunk/MySql.Data.Entity/Provider/ProviderServices.cs
trunk/MySql.Data.Entity/Provider/Statements/InsertStatement.cs
trunk/MySql.Data.Entity/Provider/Statements/UpdateStatement.cs
trunk/MySql.Data.Entity/Tests/InsertTests.cs
trunk/MySql.Data.Entity/Tests/ProceduresAndFunctions.cs
trunk/MySql.Data.Entity/Tests/Properties/procs.sql
trunk/MySql.Data/Provider/Source/CharSetMap.cs
Log:
fixed inserts and updates by implementing the returning sql portion of the command tree. test suite now fully working.
Modified: trunk/MySql.Data/Provider/Source/CharSetMap.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/CharSetMap.cs 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data/Provider/Source/CharSetMap.cs 2009-02-25 19:26:34 UTC (rev 1513)
@@ -37,6 +37,7 @@
private static Dictionary<string, string> defaultCollations;
private static Dictionary<string, int> maxLengths;
private static Dictionary<string, CharacterSet> mapping;
+ private static object lockObject;
#else
private static Hashtable mapping;
#endif
@@ -45,6 +46,7 @@
// the mapping once
static CharSetMap()
{
+ lockObject = new Object();
InitializeMapping();
}
@@ -166,7 +168,7 @@
internal static string GetDefaultCollation(string charset, MySqlConnection connection)
{
- lock (defaultCollations)
+ lock (lockObject)
{
if (defaultCollations == null)
InitCollections(connection);
@@ -178,9 +180,7 @@
internal static int GetMaxLength(string charset, MySqlConnection connection)
{
- // we lock on defaultCollations here too so GetDefaultCollation
- // is on the same lock as us.
- lock (defaultCollations)
+ lock (lockObject)
{
if (maxLengths == null)
InitCollections(connection);
Added: trunk/MySql.Data.Entity/Provider/Generators/FunctionFragment.cs
===================================================================
--- trunk/MySql.Data.Entity/Provider/Generators/FunctionFragment.cs (rev 0)
+++ trunk/MySql.Data.Entity/Provider/Generators/FunctionFragment.cs 2009-02-25 19:26:34 UTC (rev 1513)
@@ -0,0 +1,115 @@
+// Copyright (C) 2008-2009 Sun Microsystems, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation
+//
+// There are special exceptions to the terms and conditions of the GPL
+// as it is applied to this software. View the full text of the
+// exception in file EXCEPTIONS in the directory of this software
+// distribution.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Data.Common.CommandTrees;
+
+namespace MySql.Data.Entity
+{
+ class FunctionProcessor
+ {
+ private static readonly Dictionary<string, string> bitwiseFunctions =
+ new Dictionary<string, string>();
+ private static readonly Dictionary<string, string> dateFunctions =
+ new Dictionary<string, string>();
+ private static readonly Dictionary<string, string> stringFunctions =
+ new Dictionary<string, string>();
+ private static readonly Dictionary<string, string> mathFunctions =
+ new Dictionary<string, string>();
+ private SqlGenerator callingGenerator;
+
+ static FunctionProcessor()
+ {
+ bitwiseFunctions.Add("BitwiseAnd", "&");
+ bitwiseFunctions.Add("BitwiseNot", "!");
+ bitwiseFunctions.Add("BitwiseOr", "|");
+ bitwiseFunctions.Add("BitwiseXor", "^");
+
+ dateFunctions.Add("CurrentDateTime", "NOW()");
+ dateFunctions.Add("Year", "YEAR({0})");
+ dateFunctions.Add("Month", "MONTH({0})");
+ dateFunctions.Add("Day", "DAY({0})");
+ dateFunctions.Add("Hour", "HOUR({0})");
+ dateFunctions.Add("Minute", "MINUTE({0})");
+ dateFunctions.Add("Second", "SECOND({0})");
+
+ stringFunctions.Add("Concat", "CONCAT({0}, {1})");
+ stringFunctions.Add("IndexOf", "LOCATE({0}, {1})");
+ stringFunctions.Add("Left", "LEFT({0}, {1})");
+ stringFunctions.Add("Length", "LENGTH({0})");
+ stringFunctions.Add("LTrim", "LTRIM({0})");
+ stringFunctions.Add("Replace", "REPLACE({0}, {1}, {2})");
+ stringFunctions.Add("Reverse", "REVERSE({0})");
+ stringFunctions.Add("Right", "RIGHT({0}, {1})");
+ stringFunctions.Add("RTrim", "RTRIM({0})");
+ stringFunctions.Add("Substring", "SUBSTR({0}, {1}, {2})");
+ stringFunctions.Add("ToLower", "LOWER({0})");
+ stringFunctions.Add("ToUpper", "UPPER({0})");
+ stringFunctions.Add("Trim", "TRIM({0})");
+
+ mathFunctions.Add("Abs", "ABS({0})");
+ mathFunctions.Add("Ceiling", "CEILING({0})");
+ mathFunctions.Add("Floor", "FLOOR({0})");
+ mathFunctions.Add("Round", "ROUND({0})");
+ }
+
+ public SqlFragment Generate(DbFunctionExpression e, SqlGenerator caller)
+ {
+ callingGenerator = caller;
+ if (bitwiseFunctions.ContainsKey(e.Function.Name))
+ return BitwiseFunction(e);
+ else if (dateFunctions.ContainsKey(e.Function.Name))
+ return GenericFunction(dateFunctions, e);
+ else if (stringFunctions.ContainsKey(e.Function.Name))
+ return GenericFunction(stringFunctions, e);
+ else if (mathFunctions.ContainsKey(e.Function.Name))
+ return GenericFunction(mathFunctions, e);
+ return null;
+ }
+
+ private SqlFragment BitwiseFunction(DbFunctionExpression e)
+ {
+ StringBuilder sql = new StringBuilder();
+
+ int arg = 0;
+ if (e.Arguments.Count > 1)
+ sql.AppendFormat("({0})", e.Arguments[arg++].Accept(callingGenerator));
+
+ sql.AppendFormat(" {0} ({1})", bitwiseFunctions[e.Function.Name],
+ e.Arguments[arg].Accept(callingGenerator));
+ return new LiteralFragment(sql.ToString());
+ }
+
+ private SqlFragment GenericFunction(Dictionary<string,string> funcs,
+ DbFunctionExpression e)
+ {
+ SqlFragment[] frags = new SqlFragment[e.Arguments.Count];
+
+ for (int i=0; i < e.Arguments.Count; i++)
+ frags[i] = e.Arguments[i].Accept(callingGenerator);
+
+ string sql = String.Format(funcs[e.Function.Name], frags);
+ return new LiteralFragment(sql);
+ }
+ }
+}
Deleted: trunk/MySql.Data.Entity/Provider/Generators/FunctionProcessor
===================================================================
--- trunk/MySql.Data.Entity/Provider/Generators/FunctionProcessor 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data.Entity/Provider/Generators/FunctionProcessor 2009-02-25 19:26:34 UTC (rev 1513)
@@ -1,115 +0,0 @@
-// Copyright (C) 2008-2009 Sun Microsystems, Inc.
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as published by
-// the Free Software Foundation
-//
-// There are special exceptions to the terms and conditions of the GPL
-// as it is applied to this software. View the full text of the
-// exception in file EXCEPTIONS in the directory of this software
-// distribution.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Data.Common.CommandTrees;
-
-namespace MySql.Data.Entity
-{
- class FunctionFragment
- {
- private static readonly Dictionary<string, string> bitwiseFunctions =
- new Dictionary<string, string>();
- private static readonly Dictionary<string, string> dateFunctions =
- new Dictionary<string, string>();
- private static readonly Dictionary<string, string> stringFunctions =
- new Dictionary<string, string>();
- private static readonly Dictionary<string, string> mathFunctions =
- new Dictionary<string, string>();
- private SqlGenerator callingGenerator;
-
- static FunctionFragment()
- {
- bitwiseFunctions.Add("BitwiseAnd", "&");
- bitwiseFunctions.Add("BitwiseNot", "!");
- bitwiseFunctions.Add("BitwiseOr", "|");
- bitwiseFunctions.Add("BitwiseXor", "^");
-
- dateFunctions.Add("CurrentDateTime", "NOW()");
- dateFunctions.Add("Year", "YEAR({0})");
- dateFunctions.Add("Month", "MONTH({0})");
- dateFunctions.Add("Day", "DAY({0})");
- dateFunctions.Add("Hour", "HOUR({0})");
- dateFunctions.Add("Minute", "MINUTE({0})");
- dateFunctions.Add("Second", "SECOND({0})");
-
- stringFunctions.Add("Concat", "CONCAT({0}, {1})");
- stringFunctions.Add("IndexOf", "LOCATE({0}, {1})");
- stringFunctions.Add("Left", "LEFT({0}, {1})");
- stringFunctions.Add("Length", "LENGTH({0})");
- stringFunctions.Add("LTrim", "LTRIM({0})");
- stringFunctions.Add("Replace", "REPLACE({0}, {1}, {2})");
- stringFunctions.Add("Reverse", "REVERSE({0})");
- stringFunctions.Add("Right", "RIGHT({0}, {1})");
- stringFunctions.Add("RTrim", "RTRIM({0})");
- stringFunctions.Add("Substring", "SUBSTR({0}, {1}, {2})");
- stringFunctions.Add("ToLower", "LOWER({0})");
- stringFunctions.Add("ToUpper", "UPPER({0})");
- stringFunctions.Add("Trim", "TRIM({0})");
-
- mathFunctions.Add("Abs", "ABS({0})");
- mathFunctions.Add("Ceiling", "CEILING({0})");
- mathFunctions.Add("Floor", "FLOOR({0})");
- mathFunctions.Add("Round", "ROUND({0})");
- }
-
- public SqlFragment Generate(DbFunctionExpression e, SqlGenerator caller)
- {
- callingGenerator = caller;
- if (bitwiseFunctions.ContainsKey(e.Function.Name))
- return BitwiseFunction(e);
- else if (dateFunctions.ContainsKey(e.Function.Name))
- return GenericFunction(dateFunctions, e);
- else if (stringFunctions.ContainsKey(e.Function.Name))
- return GenericFunction(stringFunctions, e);
- else if (mathFunctions.ContainsKey(e.Function.Name))
- return GenericFunction(mathFunctions, e);
- return null;
- }
-
- private SqlFragment BitwiseFunction(DbFunctionExpression e)
- {
- StringBuilder sql = new StringBuilder();
-
- int arg = 0;
- if (e.Arguments.Count > 1)
- sql.AppendFormat("({0})", e.Arguments[arg++].Accept(callingGenerator));
-
- sql.AppendFormat(" {0} ({1})", bitwiseFunctions[e.Function.Name],
- e.Arguments[arg].Accept(callingGenerator));
- return new LiteralFragment(sql.ToString());
- }
-
- private SqlFragment GenericFunction(Dictionary<string,string> funcs,
- DbFunctionExpression e)
- {
- SqlFragment[] frags = new SqlFragment[e.Arguments.Count];
-
- for (int i=0; i < e.Arguments.Count; i++)
- frags[i] = e.Arguments[i].Accept(callingGenerator);
-
- string sql = String.Format(funcs[e.Function.Name], frags);
- return new LiteralFragment(sql);
- }
- }
-}
Added: trunk/MySql.Data.Entity/Provider/Generators/FunctionProcessor.cs
===================================================================
--- trunk/MySql.Data.Entity/Provider/Generators/FunctionProcessor.cs (rev 0)
+++ trunk/MySql.Data.Entity/Provider/Generators/FunctionProcessor.cs 2009-02-25 19:26:34 UTC (rev 1513)
@@ -0,0 +1,115 @@
+// Copyright (C) 2008-2009 Sun Microsystems, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation
+//
+// There are special exceptions to the terms and conditions of the GPL
+// as it is applied to this software. View the full text of the
+// exception in file EXCEPTIONS in the directory of this software
+// distribution.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Data.Common.CommandTrees;
+
+namespace MySql.Data.Entity
+{
+ class FunctionProcessor
+ {
+ private static readonly Dictionary<string, string> bitwiseFunctions =
+ new Dictionary<string, string>();
+ private static readonly Dictionary<string, string> dateFunctions =
+ new Dictionary<string, string>();
+ private static readonly Dictionary<string, string> stringFunctions =
+ new Dictionary<string, string>();
+ private static readonly Dictionary<string, string> mathFunctions =
+ new Dictionary<string, string>();
+ private SqlGenerator callingGenerator;
+
+ static FunctionProcessor()
+ {
+ bitwiseFunctions.Add("BitwiseAnd", "&");
+ bitwiseFunctions.Add("BitwiseNot", "!");
+ bitwiseFunctions.Add("BitwiseOr", "|");
+ bitwiseFunctions.Add("BitwiseXor", "^");
+
+ dateFunctions.Add("CurrentDateTime", "NOW()");
+ dateFunctions.Add("Year", "YEAR({0})");
+ dateFunctions.Add("Month", "MONTH({0})");
+ dateFunctions.Add("Day", "DAY({0})");
+ dateFunctions.Add("Hour", "HOUR({0})");
+ dateFunctions.Add("Minute", "MINUTE({0})");
+ dateFunctions.Add("Second", "SECOND({0})");
+
+ stringFunctions.Add("Concat", "CONCAT({0}, {1})");
+ stringFunctions.Add("IndexOf", "LOCATE({0}, {1})");
+ stringFunctions.Add("Left", "LEFT({0}, {1})");
+ stringFunctions.Add("Length", "LENGTH({0})");
+ stringFunctions.Add("LTrim", "LTRIM({0})");
+ stringFunctions.Add("Replace", "REPLACE({0}, {1}, {2})");
+ stringFunctions.Add("Reverse", "REVERSE({0})");
+ stringFunctions.Add("Right", "RIGHT({0}, {1})");
+ stringFunctions.Add("RTrim", "RTRIM({0})");
+ stringFunctions.Add("Substring", "SUBSTR({0}, {1}, {2})");
+ stringFunctions.Add("ToLower", "LOWER({0})");
+ stringFunctions.Add("ToUpper", "UPPER({0})");
+ stringFunctions.Add("Trim", "TRIM({0})");
+
+ mathFunctions.Add("Abs", "ABS({0})");
+ mathFunctions.Add("Ceiling", "CEILING({0})");
+ mathFunctions.Add("Floor", "FLOOR({0})");
+ mathFunctions.Add("Round", "ROUND({0})");
+ }
+
+ public SqlFragment Generate(DbFunctionExpression e, SqlGenerator caller)
+ {
+ callingGenerator = caller;
+ if (bitwiseFunctions.ContainsKey(e.Function.Name))
+ return BitwiseFunction(e);
+ else if (dateFunctions.ContainsKey(e.Function.Name))
+ return GenericFunction(dateFunctions, e);
+ else if (stringFunctions.ContainsKey(e.Function.Name))
+ return GenericFunction(stringFunctions, e);
+ else if (mathFunctions.ContainsKey(e.Function.Name))
+ return GenericFunction(mathFunctions, e);
+ return null;
+ }
+
+ private SqlFragment BitwiseFunction(DbFunctionExpression e)
+ {
+ StringBuilder sql = new StringBuilder();
+
+ int arg = 0;
+ if (e.Arguments.Count > 1)
+ sql.AppendFormat("({0})", e.Arguments[arg++].Accept(callingGenerator));
+
+ sql.AppendFormat(" {0} ({1})", bitwiseFunctions[e.Function.Name],
+ e.Arguments[arg].Accept(callingGenerator));
+ return new LiteralFragment(sql.ToString());
+ }
+
+ private SqlFragment GenericFunction(Dictionary<string,string> funcs,
+ DbFunctionExpression e)
+ {
+ SqlFragment[] frags = new SqlFragment[e.Arguments.Count];
+
+ for (int i=0; i < e.Arguments.Count; i++)
+ frags[i] = e.Arguments[i].Accept(callingGenerator);
+
+ string sql = String.Format(funcs[e.Function.Name], frags);
+ return new LiteralFragment(sql);
+ }
+ }
+}
Modified: trunk/MySql.Data.Entity/Provider/Generators/InsertGenerator.cs
===================================================================
--- trunk/MySql.Data.Entity/Provider/Generators/InsertGenerator.cs 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data.Entity/Provider/Generators/InsertGenerator.cs 2009-02-25 19:26:34 UTC (rev 1513)
@@ -19,9 +19,13 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System.Text;
+using System.Collections.Generic;
using System.Data.Common.CommandTrees;
using System.Data.Metadata.Edm;
using MySql.Data.MySqlClient;
+using System.Data.Common;
+using System.Diagnostics;
+using System;
namespace MySql.Data.Entity
{
@@ -40,8 +44,24 @@
statement.Sets.Add(setClause.Property.Accept(this));
foreach (DbSetClause setClause in commandTree.SetClauses)
- statement.Values.Add(setClause.Value.Accept(this));
+ {
+ DbExpression value = setClause.Value;
+ SqlFragment valueFragment = value.Accept(this);
+ statement.Values.Add(valueFragment);
+ if (values == null)
+ values = new Dictionary<EdmMember, SqlFragment>();
+
+ if (value.ExpressionKind != DbExpressionKind.Null)
+ {
+ EdmMember property = ((DbPropertyExpression)setClause.Property).Property;
+ values.Add(property, valueFragment);
+ }
+ }
+
+ if (commandTree.Returning != null)
+ statement.ReturningSelect = GenerateReturningSql(commandTree, commandTree.Returning);
+
return statement.ToString();
}
}
Modified: trunk/MySql.Data.Entity/Provider/Generators/SelectGenerator.cs
===================================================================
--- trunk/MySql.Data.Entity/Provider/Generators/SelectGenerator.cs 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data.Entity/Provider/Generators/SelectGenerator.cs 2009-02-25 19:26:34 UTC (rev 1513)
@@ -191,31 +191,6 @@
return s;
}
- private void VisitNewInstanceExpression(SelectStatement select,
- DbNewInstanceExpression expression)
- {
- Debug.Assert(expression.ResultType.EdmType is RowType);
-
- RowType row = expression.ResultType.EdmType as RowType;
-
- for (int i = 0; i < expression.Arguments.Count; i++)
- {
- ColumnFragment col = null;
-
- SqlFragment fragment = expression.Arguments[i].Accept(this);
- if (fragment is ColumnFragment)
- col = fragment as ColumnFragment;
- else
- {
- col = new ColumnFragment(null, null);
- col.Literal = fragment;
- }
-
- col.ColumnAlias = row.Properties[i].Name;
- select.Columns.Add(col);
- }
- }
-
public override SqlFragment Visit(DbProjectExpression expression)
{
SelectStatement select = VisitInputExpressionEnsureSelect(expression.Input.Expression,
Modified: trunk/MySql.Data.Entity/Provider/Generators/SqlGenerator.cs
===================================================================
--- trunk/MySql.Data.Entity/Provider/Generators/SqlGenerator.cs 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data.Entity/Provider/Generators/SqlGenerator.cs 2009-02-25 19:26:34 UTC (rev 1513)
@@ -35,7 +35,8 @@
private int parameterCount = 1;
protected Scope scope = new Scope();
protected int propertyLevel;
- public List<ColumnFragment> BoolOverrides = new List<ColumnFragment>();
+// public List<ColumnFragment> BoolOverrides = new List<ColumnFragment>();
+ protected Dictionary<EdmMember, SqlFragment> values;
public SqlGenerator()
{
@@ -263,6 +264,31 @@
return VisitBinaryExpression(expression.Arguments[0], expression.Arguments[1], op);
}
+ protected void VisitNewInstanceExpression(SelectStatement select,
+ DbNewInstanceExpression expression)
+ {
+ Debug.Assert(expression.ResultType.EdmType is RowType);
+
+ RowType row = expression.ResultType.EdmType as RowType;
+
+ for (int i = 0; i < expression.Arguments.Count; i++)
+ {
+ ColumnFragment col = null;
+
+ SqlFragment fragment = expression.Arguments[i].Accept(this);
+ if (fragment is ColumnFragment)
+ col = fragment as ColumnFragment;
+ else
+ {
+ col = new ColumnFragment(null, null);
+ col.Literal = fragment;
+ }
+
+ col.ColumnAlias = row.Properties[i].Name;
+ select.Columns.Add(col);
+ }
+ }
+
public override SqlFragment Visit(DbTreatExpression expression)
{
throw new NotSupportedException();
@@ -412,6 +438,37 @@
return inputFragment;
}
+ protected SelectStatement GenerateReturningSql(DbModificationCommandTree tree, DbExpression returning)
+ {
+ SelectStatement select = new SelectStatement();
+
+ Debug.Assert(returning is DbNewInstanceExpression);
+ VisitNewInstanceExpression(select, returning as DbNewInstanceExpression);
+
+ select.From = (InputFragment)tree.Target.Expression.Accept(this);
+
+ ListFragment where = new ListFragment();
+ where.Append(" row_count() > 0");
+
+ EntitySetBase table = ((DbScanExpression)tree.Target.Expression).Target;
+ bool foundIdentity = false;
+ foreach (EdmMember keyMember in table.ElementType.KeyMembers)
+ {
+ SqlFragment value;
+ if (!values.TryGetValue(keyMember, out value))
+ {
+ if (foundIdentity)
+ throw new NotSupportedException();
+ foundIdentity = true;
+ value = new LiteralFragment("last_insert_id()");
+ }
+ where.Append(String.Format(" AND `{0}`=", keyMember));
+ where.Append(value);
+ }
+ select.Where = where;
+ return select;
+ }
+
#region Private Methods
SqlFragment VisitBinaryExpression(DbExpression left, DbExpression right, string op)
Modified: trunk/MySql.Data.Entity/Provider/Generators/UpdateGenerator.cs
===================================================================
--- trunk/MySql.Data.Entity/Provider/Generators/UpdateGenerator.cs 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data.Entity/Provider/Generators/UpdateGenerator.cs 2009-02-25 19:26:34 UTC (rev 1513)
@@ -23,6 +23,7 @@
using System.Data.Common.CommandTrees;
using System.Data.Metadata.Edm;
using MySql.Data.MySqlClient;
+using System.Collections.Generic;
namespace MySql.Data.Entity
{
@@ -40,11 +41,25 @@
foreach (DbSetClause setClause in commandTree.SetClauses)
{
statement.Properties.Add(setClause.Property.Accept(this));
- statement.Values.Add(setClause.Value.Accept(this));
+ DbExpression value = setClause.Value;
+ SqlFragment valueFragment = value.Accept(this);
+ statement.Values.Add(valueFragment);
+
+ if (values == null)
+ values = new Dictionary<EdmMember, SqlFragment>();
+
+ if (value.ExpressionKind != DbExpressionKind.Null)
+ {
+ EdmMember property = ((DbPropertyExpression)setClause.Property).Property;
+ values.Add(property, valueFragment);
+ }
}
statement.Where = commandTree.Predicate.Accept(this);
+ if (commandTree.Returning != null)
+ statement.ReturningSelect = GenerateReturningSql(commandTree, commandTree.Returning);
+
return statement.ToString();
}
}
Modified: trunk/MySql.Data.Entity/Provider/MySql.Data.Entity.csproj
===================================================================
--- trunk/MySql.Data.Entity/Provider/MySql.Data.Entity.csproj 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data.Entity/Provider/MySql.Data.Entity.csproj 2009-02-25 19:26:34 UTC (rev 1513)
@@ -80,9 +80,6 @@
<Name>MySql.Data</Name>
</ProjectReference>
</ItemGroup>
- <ItemGroup>
- <None Include="Generators\FunctionProcessor" />
- </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Modified: trunk/MySql.Data.Entity/Provider/ProviderServices.cs
===================================================================
--- trunk/MySql.Data.Entity/Provider/ProviderServices.cs 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data.Entity/Provider/ProviderServices.cs 2009-02-25 19:26:34 UTC (rev 1513)
@@ -79,16 +79,6 @@
foreach (DbParameter p in generator.Parameters)
cmd.Parameters.Add(p);
- if (commandTree is DbInsertCommandTree)
- {
- MySqlConnection c = new MySqlConnection("server=localhost;uid=root;database=test");
- c.Open();
- cmd.Connection = c;
- MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
- reader.Close();
- int i = reader.RecordsAffected;
- }
-
return CreateCommandDefinition(cmd);
}
Modified: trunk/MySql.Data.Entity/Provider/Statements/InsertStatement.cs
===================================================================
--- trunk/MySql.Data.Entity/Provider/Statements/InsertStatement.cs 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data.Entity/Provider/Statements/InsertStatement.cs 2009-02-25 19:26:34 UTC (rev 1513)
@@ -34,6 +34,7 @@
public InputFragment Target { get; set; }
public List<SqlFragment> Sets { get; private set; }
public List<SqlFragment> Values { get; private set; }
+ public SelectStatement ReturningSelect;
public override void WriteSql(StringBuilder sql)
{
@@ -49,6 +50,12 @@
sql.Append("(");
WriteList(Values, sql);
sql.Append(")");
+
+ if (ReturningSelect != null)
+ {
+ sql.Append(";\r\n");
+ ReturningSelect.WriteSql(sql);
+ }
}
}
}
Modified: trunk/MySql.Data.Entity/Provider/Statements/UpdateStatement.cs
===================================================================
--- trunk/MySql.Data.Entity/Provider/Statements/UpdateStatement.cs 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data.Entity/Provider/Statements/UpdateStatement.cs 2009-02-25 19:26:34 UTC (rev 1513)
@@ -34,6 +34,7 @@
public List<SqlFragment> Properties { get; private set; }
public List<SqlFragment> Values { get; private set; }
public SqlFragment Where { get; set; }
+ public SelectStatement ReturningSelect;
public override void WriteSql(StringBuilder sql)
{
@@ -55,6 +56,11 @@
sql.Append(" WHERE ");
Where.WriteSql(sql);
}
+ if (ReturningSelect != null)
+ {
+ sql.Append(";\r\n");
+ ReturningSelect.WriteSql(sql);
+ }
}
}
}
Modified: trunk/MySql.Data.Entity/Tests/InsertTests.cs
===================================================================
--- trunk/MySql.Data.Entity/Tests/InsertTests.cs 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data.Entity/Tests/InsertTests.cs 2009-02-25 19:26:34 UTC (rev 1513)
@@ -52,7 +52,7 @@
using (testEntities context = new testEntities())
{
Company c = new Company();
- //c.Id = lastId + 1;
+ c.Id = 23;
c.Name = "Yoyo";
c.NumEmployees = 486;
c.DateBegan = dateBegan;
@@ -62,17 +62,8 @@
c.Address.ZipCode = "44558";
context.AddToCompanies(c);
- try
- {
- int result = context.SaveChanges();
- }
- catch (OptimisticConcurrencyException ex)
- {
- context.Refresh(RefreshMode.StoreWins, c);
- context.SaveChanges();
- }
+ int result = context.SaveChanges();
-
DataTable afterInsert = new DataTable();
da.Fill(afterInsert);
lastRow = afterInsert.Rows[afterInsert.Rows.Count - 1];
Modified: trunk/MySql.Data.Entity/Tests/ProceduresAndFunctions.cs
===================================================================
--- trunk/MySql.Data.Entity/Tests/ProceduresAndFunctions.cs 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data.Entity/Tests/ProceduresAndFunctions.cs 2009-02-25 19:26:34 UTC (rev 1513)
@@ -37,6 +37,7 @@
public ProceduresAndFunctions()
: base()
{
+ csAdditions += ";logging=true;";
}
[Test]
@@ -76,7 +77,7 @@
var q = from a in context.Authors
where a.Name == "Don Box"
select a;
- foreach (Author a in context.Authors)
+ foreach (Author a in q)
a.Name = "Dummy";
context.SaveChanges();
}
Modified: trunk/MySql.Data.Entity/Tests/Properties/procs.sql
===================================================================
--- trunk/MySql.Data.Entity/Tests/Properties/procs.sql 2009-02-24 18:04:51 UTC (rev 1512)
+++ trunk/MySql.Data.Entity/Tests/Properties/procs.sql 2009-02-25 19:26:34 UTC (rev 1513)
@@ -13,8 +13,7 @@
DELETE FROM authors WHERE id=theid;
END $$
-CREATE FUNCTION UpdateAuthor(theid int, thename varchar(20), theage int) RETURNS INT
+CREATE PROCEDURE UpdateAuthor(theid int, thename varchar(20), theage int)
BEGIN
UPDATE authors SET `name`=thename, age=theage WHERE id=theid;
- RETURN 0;
END $$
| Thread |
|---|
| • Connector/NET commit: r1513 - in trunk: MySql.Data/Provider/Source MySql.Data.Entity/Provider MySql.Data.Entity/Provider/Generators MySql.Data.Entity/... | rburnett | 25 Feb |