Help - MYSQL and Swi Prolog

I’m using: SWI-Prolog version ???

I want the code to: insert an average to mysql, but it btings out an error.

What I’m getting, my ODBC and MYSQL is:

My code looks like this:

conexion12:-
    odbc_connect('tienda_swi',_,
                 [user(root),
                  password('root'),
                  alias(tienda_swi),
                  open(once)]).

insertar_registros(X,Y):-
    odbc_query(tienda_swi,"INSERT INTO promedio(apellido, prom) VALUES(`~w`,`~w`)"-[X,Y],
affected(F)).

parcial1(X,A,B,C,Y):-
    Y is round((A+B+C)/3),apru(Y),
    insertar_registros(Y,X).

apru(Y):- Y =< 10.4, write('Desaprobo.').
apru(Y):- Y >= 10.5,  write('Aprobo.').

It looks like the ODBC connection is working based on

ERROR: ODBC: State 42522: [MySQL][ODBC 8.0(w) Driver][mysqld-5.7.24]Unknown column '12' in 'field list'

but as I have not used MySQL with ODBC I would start from the ground up in resolving this problem.

  1. Check the ODBC configuration using iusql.

When I created a Wiki for using ODBC with PostgreSQL it starts with checking the ODBC configuration using iusql. You should be able to do the same but instead using your ODBC configuration. If you are not on Linux then you should find a similar tool.

  1. Check ODBC connection using the SWI-Prolog DSN configuration.

The wiki also has some simple test cases. You should be able to create similar queries and get similar results using MySQL.

  1. Check your Prolog quires without using MySQL.

  2. Add some guard statements using must_be/2 for the quires connecting to MySQL, e.g.

insertar_registros(X,Y) :-
   must_be(ground,X),
   must_be(ground,Y),
   odbc_query( ... ),
   ...

There is not much more help I can give you than this without installing MySQL which is not on my task list for the day.

Also please translate the error messages in images into text as it makes it better for others seeking help on the same problem and makes it easier for us helping you to read the full error message. :grinning:

I’ve just realised it worked in other mysql I had, so it MUST have been doing something wrong in between the MYSQL and ODBC/SWI Prolog.

I’m sorry for taking your time, I’m basically new in this world.

fixed: I tried to consult the file from a txt with .pl and then worked from there, now it’s fixed. Really sorry for your time! and thank you, I’ve learned more from your post.

Now i’ll just search for a way to get the average with just 2 decimals jaja

1 Like

I assure you, you did not waste my time. If I didn’t want to take the time to answer this I would have not. :grinning:

Just yesterday I noted to someone that I see them being smarter for asking a question then spending days to years for not asking out of fear.

Your question has most of what was needed to give a reasonable answer and is easily understood. If I had MySQL installed I could have given more details.

You also get brownie points for replying back and giving useful information.

Just to let you know.

This site is hosted for free with certain limitations, one of them being a limited amount of storage space. The use of images uses a lot of storage space. Often images can have a low signal to storage ratio and so it is preferred that the information be extracted from them and converted into a format using less storage.

While we keep an eye on this at some time in the future we may have to start pruning images without consent. These images would be high on the prune list.

While I agree that the images were helpful for your question they really should be converted to something using orders of magnitude less storage space. :grinning:

1 Like