Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-07-06 16:09:08

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

safe_insert using AND in the WHERE clause

safe_insert using AND in the WHERE clause does not work; what would be the easier way to do that?
Should I use safe_query?
Thanks for your help.


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#2 2016-07-06 17:15:33

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: safe_insert using AND in the WHERE clause

Can you post the code that doesn’t work?

Offline

#3 2016-07-06 18:03:01

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: safe_insert using AND in the WHERE clause

Here is the idea:

safe_upsert(
    'txp_lang', 
    'data = "My data", event = "public"',
    'name = "my_data" AND lang = "en-gb"'
)

Edit: … and here is the error message User_Error "Duplicate entry '0' for key 'lang'"

Edit#2: Here is the INSERT command if the row does not exist:
[SQL: INSERT INTO txp_lang SET name = 'my_data' AND lang = 'en-gb', data = 'My data', event = 'public' ]

Last edited by NicolasGraph (2016-07-06 18:54:28)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#4 2016-07-06 20:28:07

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: safe_insert using AND in the WHERE clause

safe_insert('txp_lang', 'data = "My data", event = "public", name = "my_data", lang = "en-gb"');

Should work fine…
However, you’re using safe_upsert, which internally calls safe_insert, but can’t handle anything more then the most simple ‘where’ part. It’s a safe_upsert limitation. One could consider this a bug. If so, open an issue at github.

Offline

#5 2016-07-07 06:35:40

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: safe_insert using AND in the WHERE clause

ruud wrote #300218:

One could consider this a bug. If so, open an issue at github.

Thanks Ruud, I sent a pull request; let see what will happen…

Last edited by NicolasGraph (2016-07-07 06:36:04)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

Board footer

Powered by FluxBB