1

Scenario: I have a table in a mariaDB. It’s called “pages”. It just has three columns and a few entries for test purposes.

Problem: I try to create a nice PREPARE statement in SQL. I did not get it working so I ended up with the following ‘simple’ code.

PREPARE stmt from 'SELECT * FROM `pages`;';
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

It does kind of execute without errors, but it does not show a single row.

What am I missing here?

If you are asking, why I use a prepare statement for such a simple query: It is just for finding the error. The final query will be more complicated with variables etc.

Thanks in advance!

P.S.: Could be a double of Select * for mysql prepare statement not listing anything but maybe not.

Additional Info I run the code as a direct SQL Query in Sequel Pro.

RIGHT ANSWER

Joakim Danielson had the right guess.

prepare stmt from 'SELECT * FROM `pages`;'; execute stmt;
DEALLOCATE PREPARE stmt;

This works in Sequel Pro. BUT I totally recommend to not use Sequel Pros command line. Other bugs occurred one after another. Not so in the mysql CLI. Better go with your OS’ command line.

Matthi
  • 1,073
  • 8
  • 19
  • PREPPARE ?? or PREPARE – ScaisEdge May 04 '18 at 10:08
  • Why the mysql and sql flags if you're using mariadb? Are you trying to run those commands directly from the command line of mariadb or are you using a programming language like PHP? – Dave May 04 '18 at 10:24
  • @scaisEdge Thanks, but it was just a typo here, not in the real code. – Matthi May 04 '18 at 10:25
  • @Dave I am aiming to run those commands from a node app via the mysql connector https://github.com/mysqljs/mysql But for testing I run the code directly in Sequel Pro. The tag....I can dismiss it. Sequel Pro is just telling me MySQL 5.5.5-10.2.14-MariaDB. – Matthi May 04 '18 at 10:29

1 Answers1

1

This has something to do with Sequel Pro then I guess. If you first run the prepare and execute rows together it will work and show some output, at least it did for me, and then run the deallocate separately. I also tried from the command line and it worked fine there too.

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52