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

Add ability to execute procedures creation from raw SQL query #31

Open
chshersh opened this issue Oct 30, 2018 · 1 comment
Open

Add ability to execute procedures creation from raw SQL query #31

chshersh opened this issue Oct 30, 2018 · 1 comment

Comments

@chshersh
Copy link

Recently added (in #26) executeMany_ function allows to perform multiple statements, which is great! Unfortunately, it fails when I'm trying to use this function to create procedure in MySQL.

I see the following error:

ERRException (ERR {errCode = 1064, errState = "42000", errMsg = "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER //\nCREATE PROCEDURE simpleproc (OUT param1 INT)\nBEGIN\n    SELECT COUNT' at line 1"})

However, if I execute my query from MySQL REPL, everything works great 👍

I'm following this guide:

As I understand, the problem is in DELIMITER command. I wonder, whether it's possible to somehow support this workflow in mysql-haskell library? 🤔

And here is complete code:

#! /usr/bin/env cabal
{- cabal:
build-depends: base >= 4.11 && < 4.12
             , mysql-haskell ^>= 0.8.4.1
-}

{-# LANGUAGE OverloadedStrings #-}

module Main where

import Data.String (fromString)
import Database.MySQL.Base
import Database.MySQL.Connection (utf8mb4_unicode_ci)


createProc :: Query
createProc = fromString $ unlines
    [ "DELIMITER //"
    , "CREATE PROCEDURE simpleproc (OUT param1 INT)"
    , "BEGIN"
    , "    SELECT COUNT(*) INTO param1 FROM t;"
    , "END //"
    , "DELIMITER ;"
    ]

main :: IO ()
main = do
    (greet, conn) <- connectDetail ConnectInfo
        { ciHost = "localhost"
        , ciPort = 3306
        , ciUser = "mp"
        , ciPassword = "mp"
        , ciDatabase = "mp"
        , ciCharset = utf8mb4_unicode_ci
        }
    print greet

    print =<< mapM (executeMany_ conn) [createProc]
@winterland1989
Copy link
Owner

winterland1989 commented Oct 30, 2018

From stack overflow:

Note that the DELIMITER keyword is a function of the command line mysql client (and some other clients) only and not a regular MySQL language feature. It won't work if you tried to pass it through a programming language API to MySQL

So my question is, can this procedure be added without changing DELIMITER?

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

2 participants