# Sql connector and variables

**URL:** <https://forum.bubble.io/t/sql-connector-and-variables/12910>\
**Category:** Need help\
**Created:** [April 27, 2017, 1:56pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910 "2017-04-27T13:56:07Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![victoriys2005](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/victoriys2005/32/11826_2.png) [@victoriys2005](https://forum.bubble.io/u/victoriys2005)\
**Post date:** [April 27, 2017, 1:56pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/1 "2017-04-27T13:56:07Z")

</div>

I tried to search for an answer to my new question on the forum, but I could not find it.

I’m interested in the ability to specify a custom variable that does not match any column.

Is it possible to use variables in sql connectore in queries? In sql we use @ for this.

How to correctly set the syntax in sql connector?  
Our query in mysql is working. But sql connector produces an error: an error in the query syntax in the next line of the variable declaration.

---

<div class="post-metadata">

**Author:** ![mishav](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mishav/32/6420_2.png) [@mishav](https://forum.bubble.io/u/mishav)\
**Post date:** [April 27, 2017, 2:55pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/2 "2017-04-27T14:55:53Z")

</div>

It doesn’t like multiline queries.  
Also it requires a row limit.

What are you trying?

---

<div class="post-metadata">

**Author:** ![victoriys2005](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/victoriys2005/32/11826_2.png) [@victoriys2005](https://forum.bubble.io/u/victoriys2005)\
**Post date:** [April 27, 2017, 3:19pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/3 "2017-04-27T15:19:31Z")

</div>

set @pass=?;  
insert into user  
set id\_user=(select distinct concat(‘u’, (select (count(id\_user)+1) from (select id\_user from user as tmp ) as tmp1)) from user as tmp2),  
FIO=?,  
email=?,  
password=sha1(@pass)  
;

---

<div class="post-metadata">

**Author:** ![mishav](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mishav/32/6420_2.png) [@mishav](https://forum.bubble.io/u/mishav)\
**Post date:** [April 27, 2017, 3:27pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/4 "2017-04-27T15:27:48Z")

</div>

Suggested changes:

- Remove newlines to make it all on one line.

- Possibly multi statement (ie. scripts) aren’t supported, if so make it just one insert, without setting a variable first, and without semicolons.

- If you really do need variables and multi statements, perhaps create a stored procedure.

---

<div class="post-metadata">

**Author:** ![victoriys2005](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/victoriys2005/32/11826_2.png) [@victoriys2005](https://forum.bubble.io/u/victoriys2005)\
**Post date:** [April 27, 2017, 3:34pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/5 "2017-04-27T15:34:17Z")

</div>

Thank you again!

How to create a stored procedure in bubble?

---

<div class="post-metadata">

**Author:** ![mishav](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mishav/32/6420_2.png) [@mishav](https://forum.bubble.io/u/mishav)\
**Post date:** [April 27, 2017, 3:50pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/6 "2017-04-27T15:50:18Z")

</div>

> [@victoriys2005](#):
>
> How to create a stored procedure in bubble?

In the database, not in Bubble, have a read of MySQL docs.

Good luck!

---

<div class="post-metadata">

**Author:** ![victoriys2005](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/victoriys2005/32/11826_2.png) [@victoriys2005](https://forum.bubble.io/u/victoriys2005)\
**Post date:** [May 17, 2017, 9:02am UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/7 "2017-05-17T09:02:16Z")

</div>

Thank you for all your reply.

We have a new question.  
How to call a stored procedure via sql database connector?

Here is the query: call get\_id\_zakaz(id\_user=?, creation\_date=?);  
Error name: query issue unknown column id\_user in field list

On the mysql side everything works fine. Can you help us?

---

<div class="post-metadata">

**Author:** ![victoriys2005](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/victoriys2005/32/11826_2.png) [@victoriys2005](https://forum.bubble.io/u/victoriys2005)\
**Post date:** [May 17, 2017, 7:34pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/8 "2017-05-17T19:34:29Z")

</div>

I will slightly rewrite the question.  
How to pass the variable (parameter) of the calling procedure via sql database connector?

---

<div class="post-metadata">

**Author:** ![mishav](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mishav/32/6420_2.png) [@mishav](https://forum.bubble.io/u/mishav)\
**Post date:** [May 18, 2017, 10:35am UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/9 "2017-05-18T10:35:52Z")

</div>

> [@victoriys2005](#):
>
> How to call a stored procedure via sql database connector?

Using your example, the simplest way is with positional parameters:  
`call get_id_zakaz(?, ?)`

Parameters  
$1 Name: id\_user Type: text test value: blah  
$2 Name: creation\_date Type: date test value: …

Not sure what you’d put for date, see if you get it to work with just a text parameter, and hardcode the date value on the query… then try adding in different date formats.

---

<div class="post-metadata">

**Author:** ![victoriys2005](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/victoriys2005/32/11826_2.png) [@victoriys2005](https://forum.bubble.io/u/victoriys2005)\
**Post date:** [May 18, 2017, 6:40pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/10 "2017-05-18T18:40:17Z")

</div>

Thanks for the answer.

How to transfer data (date) in the format: 2017-01-31 00:31:31? It’s mysql format “datetime”.

---

<div class="post-metadata">

**Author:** ![mishav](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mishav/32/6420_2.png) [@mishav](https://forum.bubble.io/u/mishav)\
**Post date:** [May 19, 2017, 2:41pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/11 "2017-05-19T14:41:24Z")

</div>

> [@victoriys2005](#):
>
> How to transfer data (date) in the format: 2017-01-31 00:31:31? It’s mysql format “datetime”.

Note that MySQL datetime does no converting between timezones, so it will store the date “as received”. Bubble will send the date in the timezone of its server, i.e. UTC.

Action query:  
`call get_id_zakaz(?, ?)`

Parameter:  
$1 Name: id\_user Type: text test value: blah  
$2 Name: `creation_date`, Type: `date`, Test value: `2017-01-31 00:31:31`

Then in a workflow you can add an action Data \> name\_of\_your\_query, and put a dynamic date value in.

Good luck!

---

<div class="post-metadata">

**Author:** ![victoriys2005](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/victoriys2005/32/11826_2.png) [@victoriys2005](https://forum.bubble.io/u/victoriys2005)\
**Post date:** [May 24, 2017, 9:12pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/12 "2017-05-24T21:12:50Z")

</div>

Your answer pushed us to one thought and we were able to solve our problem. Thank you so much.

But we have one more question 😋  
Why can sql connector not see the data that is returned from the stored procedure? Neither the variable “out” nor the result of the selection (the select statement) made in the stored procedure.

---

<div class="post-metadata">

**Author:** ![mishav](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mishav/32/6420_2.png) [@mishav](https://forum.bubble.io/u/mishav)\
**Post date:** [May 26, 2017, 5:56am UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/13 "2017-05-26T05:56:02Z")

</div>

> [@victoriys2005](#):
>
> Why can sql connector not see the data that is returned from the stored procedure? Neither the variable “out” nor the result of the selection (the select statement) made in the stored procedure.

I don’t know why it doesn’t see the result, perhaps a bug with the SQL Connector. Can you ask Emmanuel, or raise a bug report?

A possible workaround is to run the stored procedure, then do another query to retrieve the results from the tables or views.

---

<div class="post-metadata">

**Author:** ![victoriys2005](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/victoriys2005/32/11826_2.png) [@victoriys2005](https://forum.bubble.io/u/victoriys2005)\
**Post date:** [May 29, 2017, 2:09pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/14 "2017-05-29T14:09:48Z")

</div>

OK, thanks. The report was sent. I will keep you informed.  
We will try to solve this issue.

---

<div class="post-metadata">

**Author:** ![victoriys2005](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/victoriys2005/32/11826_2.png) [@victoriys2005](https://forum.bubble.io/u/victoriys2005)\
**Post date:** [May 30, 2017, 12:43pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/15 "2017-05-30T12:43:17Z")

</div>

Emmanuel asked to post our question on the forum.

Our post:

"We have several problems with the plugin, which did not work out at the bubles forum.

The sql connector calls the stored procedure on mysql, the incoming parameter is passed, the test values in the plugin itself are processed correctly. The query is used as a value, but when calling the query in bubble (I add it via an external API, and I select the name of the required query) sql connector does not see the outgoing parameter from the procedure, that is, the query result. At the same time, on the mysql side, the stored procedure executes correctly and the result returns. Tell me, please, what could be the reason."

As I said before - Sql connector does not see the result of executing the stored procedure. The stored procedure is “call offer\_id (?);”

Example: Id\_offer = insert\_offer(More…)  
Inside, in theory, there should be: " ‘s id\_offer\_bub\_proc"

We also posted an example application: [https://bubble.io/page?type=page&name=example&id=example-sql&tab=tabs-2](https://bubble.io/page?type=page&name=example&id=example-sql&tab=tabs-2)

All accesses have been given.  
I attached screenshots.

 ![](https://us1.discourse-cdn.com/bubble/original/2X/6/6df599c1131fa48d13608e6611b144fe01290899.jpg) ![](https://us1.discourse-cdn.com/bubble/original/2X/8/858f3ce0b1ea3246eb15601617fe233f0b688028.jpg)

---

<div class="post-metadata">

**Author:** ![emmanuel](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/emmanuel/32/27657_2.png) [@emmanuel](https://forum.bubble.io/u/emmanuel)\
**Post date:** [May 30, 2017, 1:12pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/16 "2017-05-30T13:12:35Z")

</div>

Hello,

It turns out your request returns nothing. There are no field.

 ![](https://us1.discourse-cdn.com/bubble/original/2X/3/34a73856d44defa4ee656ed371b8fef1a3d44b1f.png)

---

<div class="post-metadata">

**Author:** ![victoriys2005](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/victoriys2005/32/11826_2.png) [@victoriys2005](https://forum.bubble.io/u/victoriys2005)\
**Post date:** [May 30, 2017, 10:39pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/17 "2017-05-30T22:39:19Z")

</div>

We think that we managed to find a bug in the sql connector. When calling a stored procedure from the sql connector, it does not see the fields received in response as a result of execution. The procedure is called and correctly executed when initializing and entering test values.

But in the application it is impossible to access it via “get data from an external API”, because sql connector does not see the fields it receives. But if you first write in the query field with a “select” on the desired field. And then change the text of the request to call the stored procedure, everything works out correctly.

Look in the above application for an example.

In sql connector there are two requests: “insert\_offer” and “ins1”, in which the query text is the same, calls the same stored procedure “offer\_id”, but in “insert\_offer” does not see the field “id\_offer\_prots”, and in “ins1” sees .

---

<div class="post-metadata">

**Author:** ![bcronin7](https://avatars.discourse-cdn.com/v4/letter/b/bbce88/32.png) [@bcronin7](https://forum.bubble.io/u/bcronin7)\
**Post date:** [October 7, 2017, 11:52am UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/18 "2017-10-07T11:52:30Z")

</div>

Can anyone verify that using stored procedures in MySQL via the SQL connector actually works? This is one of the few posts on the forum that discusses this, and after following along with the back and forth, I’d say it doesn’t end well. Something like this:

call sp\_proc (?,?)

Before I invest in building something to find out, I was hoping to hear it works for others.

---

<div class="post-metadata">

**Author:** ![victoriys2005](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/victoriys2005/32/11826_2.png) [@victoriys2005](https://forum.bubble.io/u/victoriys2005)\
**Post date:** [October 8, 2017, 11:03am UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/19 "2017-10-08T11:03:10Z")

</div>

> [@bcronin7](#):
>
> call sp\_proc

Before calling the procedure “call sp\_proc”, you need to create a query “select” in the same query that is created in the sql connector, with fields that are returned by the stored procedure in msql. The main thing is that it was in one query in the sql connector

Then you need to initialize it one time, so that bubble sees these fields. Then delete the “select” and write the procedure call already. It’s like a bug.

---

<div class="post-metadata">

**Author:** ![bcronin7](https://avatars.discourse-cdn.com/v4/letter/b/bbce88/32.png) [@bcronin7](https://forum.bubble.io/u/bcronin7)\
**Post date:** [October 8, 2017, 12:11pm UTC](https://forum.bubble.io/t/sql-connector-and-variables/12910/20 "2017-10-08T12:11:37Z")

</div>

So, paraphrasing what you say, you have to trick it with a SELECT statement first, and return the fields and data types into Bubble. For example:

SELECT my\_date, my\_number, my\_text FROM my\_table WHERE my\_number \> ?

Run it, let Bubble see the results, and then replace it with …

CALL my\_proc (?) [Which returns fields like the above.]

Hopefully I’ve got that right. Seems like a pain. It would be nice to see this fixed, stored procedures are a very useful way to separate business logic and make it reusable.

[Next page](https://forum.bubble.io/t/sql-connector-and-variables/12910.md?page=2)
