Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlSyntaxError for MariaDB Database with non composable scalar valued function #36

Open
Streissi opened this issue Jun 26, 2019 · 1 comment

Comments

@Streissi
Copy link

Streissi commented Jun 26, 2019

Hi i am using EntityFramework.Functions to call my stored functions on a MariaDb database server.
Where i get the following error when i am calling my function:

System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[next_pdomatid](1)' at line 1
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.EntityFramework.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   --- End of inner exception stack trace ---
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Entity.Core.Objects.ObjectContext.CreateFunctionObjectResult[TElement](EntityCommand entityCommand, ReadOnlyCollection`1 entitySets, EdmType[] edmTypes, ExecutionOptions executionOptions)
   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass47`1.<ExecuteFunction>b__46()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass47`1.<ExecuteFunction>b__45()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, ExecutionOptions executionOptions, ObjectParameter[] parameters)
   at Pai.CCL.EF.DAL.CCLDbContext.NextPdoMatId(Int32 count) in D:\Tatmetal\CCL\Source\Pai.CCL\Pai.CCL.EF\DAL\CCLDbContext.cs:line 64
   at Pai.CCL.Services.CCLService.GetNewMaterialId() in D:\Tatmetal\CCL\Source\Pai.CCL\Pai.CCL\Services\CCLService.cs:line 129

The definition looks like following;

        [Function(FunctionType.NonComposableScalarValuedFunction, "next_pdomatid", Schema = "")]
        [return: Parameter(DbType = "int")]
        public int NextPdoMatId([Parameter(DbType = "int")]int count)
        {
            var countParameter = new ObjectParameter("count", count);

            return this.ObjectContext()
                .ExecuteFunction<int>("next_pdomatid",
                    countParameter).SingleOrDefault();
        }

When i run the function with HeidiSQL the query looks like this:

SELECT next_pdomatid('1')

and a query with the [], there i get the same error.

Is there any chance to set it up to not to use the []?

@Streissi Streissi changed the title SqlSyntaxError for MySQL Database with non composable scalar valued function SqlSyntaxError for MariaDB Database with non composable scalar valued function Jun 26, 2019
@Streissi
Copy link
Author

i think the problem is on

return $"SELECT {schema}[{functionName}]({string.Join(", ", parameterNames)})";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant