SQL plugin with MS SQL - can I use parameters in the query itself?

Seems like a dumb question I know, since I know you can use parameters, but for some reason I can’t get this update query to work no matter what I do. What’s weird though is it will work ONCE but then never again:

That’s one variation of it. I’ve tried with the ’ ’ quote marks added or not, but nothing seems to work. The query says it’s successful but nothing updates in SQL server. What’s weird though is as mentioned it will work once. Like sometimes if I edit the query and manually put the record ID to update into it, while leaving the other fields as parameters it will work once, but then try again and never a second time.

I was hoping to create a single SQL action where I can via workflow enter the table name, the field name, and then the value I want it to update to but not having any luck. Should this be possible? Just weird how it says success, but nothing updates in the SQL server, or you make a small change and it works, but then never again. So can’t tell if it’s a bug, or if pressing initialize query only works the first time (where changing parameter test values and pressing re-initialize query just ignores those or what).

Not sure if this will help, but all my paramaters are without ’ ’ and not sure why ID is in Brackets either. You can also try leaving [dbo]. out and see what happens.

Same with field [Competitor_DSL ] . Just a shot in the dark, but it something I would have tried.

Thank you, I tried so many ways, at first it was like you said no brackets etc. Then I tried with them and so on but it’s weird as it works once but not again so more just wanted to post to be sure that this is even possible. Thanks!

1 Like

What happens when you click initialize this query? Any error messages?

Hi, In adittion to Christo1,

Can you check if the login/user that you created in your SQL database for this Bubble connection has the appropriate GRANT permissions created?

Instead of updating, can you try doing this to get sure that the connection and parameters are working?

SELECT TOP 10 * FROM dbo.@table WHERE @field = @value

and also one for this:

SELECT TOP 10 * FROM dbo.@table WHERE ID = @id

Best wishes,

Juan

1 Like

It depends, sometimes I do and sometimes there’s no error. Right now I have it configured like this with no brackets or anything:

If I initialize, I get this error:

The user is db_owner and the admin user I use for everything with SQL so definitely has the permissions. I want to point out also the DB connector works fine, I have it connected and I can do delete and insert queries, but I wanted to try update using parameters so that I could have 1 query that does multiple functions (as right now my delete and insert ones I have 1 query for every table coded into the query).

Here’s what that does:

If I manually write that out:

I get this error:

But not if I put ID in quotes like this:

Then it works, and opens a popup showing all fields from the SQL table where I can pick text, numeric, etc. That’s why I was putting the quotes in my forumas in my OP since it seemed like it needed them.

If I do that:

Same issue:

So it’s really strange, if I actually type in table names, values etc it always works fine but when using parameters it always complains about syntax. That’s why I wasn’t sure if I needed quotes or brackets or something else.

I use the plugin extensively and it works for me. I have however never tried to dynamically find a filed or table with parameters and think this might be your issue. You may need to create a seperate query per table.

Try: SELECT TOP 10 * FROM dbo.Buildings WHERE id = @id
also make sure you are using the table and field names in the same case as they are in the actual dB as that might matter too.

Here is a Gif showing many different queries for the same connection (none of them use a parameter to reference the Table though):
Shared with CloudApp

Found this : Limitations of Table-Valued Parameters

There are several limitations to table-valued parameters:

  • You cannot pass table-valued parameters to CLR user-defined functions.
  • Table-valued parameters can only be indexed to support UNIQUE or PRIMARY KEY constraints. SQL Server does not maintain statistics on table-valued parameters.
  • Table-valued parameters are read-only in Transact-SQL code. You cannot update the column values in the rows of a table-valued parameter and you cannot insert or delete rows. To modify the data that is passed to a stored procedure or parameterized statement in table-valued parameter, you must insert the data into a temporary table or into a table variable.
  • You cannot use ALTER TABLE statements to modify the design of table-valued parameters.

HERE: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/table-valued-parameters

1 Like

That query is what I have it at now. Here’s a quick video I did just to show I’m not crazy. It works once and then never again, it’s so weird!

https://infusionit0-my.sharepoint.com/:v:/g/personal/lmoreau_infusion-it_com/EaOPF_WjUtdAojS0qzy3DUEB8KInW9--CaJI1cIyYzfvpw?e=pYTfIs

As you can see the first time I do it it pulls the data from SQL, but if I change SQL it just never updates ever again in Bubble. :slight_smile:

Bubble stores the last query. To force it to do another query add a false paramater, not referenced in the query iteself, called refresh or any name you’d like.

In your Bubble editor fill the refresh field with current date/time formatted as ISO or any other time parameter that would be different each time you run it. This is purely to trick Bubble and has no relationship with your data.

This way, Bubble is forced to access the DB each time it is run as the refresh “parameter” is different to the last run

image

Thanks same issue :frowning:

And then I set it to be current date / time in ISO but tried other formats as well, it still only shows the first retrieved value and never updates. I’ve refreshed the page but same old.

I appreciate your help, think I’m going to call it on this one!

Sorry that it did not work for you

1 Like

Hi

Did you ever manage to resolve this? I’ve got exactly the same problem and can’t work out what is going on. Wondering if it is not a bug?

No I gave up and we went with a different solution as I couldn’t make it work. Pretty sure it is a bug though as it would work for me once, and then never again. I’d literally do a test to have it update a record and it would work as you’d expect, then I change a value to have it change the record back and it wouldn’t ever work again.

It looks like you are putting the SQL results into a text field. Instead, put the results into a repeating group (hidden somewhere on page). Then have the text field point at 's list of SQL_Building_Details: first item’s Competitor_DSL. Each time the user enters a new value into the search Field, have a workflow 1) clear the Repeating Group and then 2) display the Repeating Group.
If that doesn’t work, try forcing the Repeating Group to refresh using the date/time technique but instead of formatting the date, do extract: Unix Timestamp.

Disclaimer: I work with MySQL, not MS SQL, but I’ve gotten good results using the steps above. Hope it works!

Joey

No that’s not the issue, I can’t even get the plugin to initialize and allow usage in a workflow, the plugin just always fails or gives syntax errors. You’ll only use one parameter, like @table in the query, with the rest of the values all hard coded. That will work fine. You then tweak it to have @table and also @id as parameters, try it and it fails. You remove the @id parameter, put it back 100% the way it was a moment ago where only @table is a parameter and it fails giving syntax error. Copy that query, create a new one, paste it into the new one, works first time you try it, then syntax error every time after that.

From searching the forums on here it seems like this plugin isn’t really made for MS SQL as almost all the issues people have with it are always relating to MS SQL.

I see. Sounds like you’re correct - I haven’t had these issues with MySQL.

@joeyg
I am having an issue with a MYSQL query.

error

I am unable to find a correct syntax? or is there any other way/query to do this?

Regards
Chirag

Try this:

select * from…where industry like ? limit 10;

Parameters
$1 Name industry type=text

Then use %% (no quotes) as the parameter when you call the API. You can test the syntax by entering %% in the Test value and pressing the “Initialize this query” button.

@joeyg
Peferct.
Thanks a lot.
Regards
Chirag