Insert into ... mysql

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Insert into ... mysql

César Espinoza
Hi all  !!

I did! I can now connect and query to mysql

fpc 2.2.4, console, Macosx 10.5 leopard, Mac book Intel

But I can't (may be I dont know :-( ) insert data in a table
------------
 connect mysql  ... ok
  select db ... ok
.....
  new(consulta);
  consultastr:='INSERT INTO lugares (lugar) values (''Sala'')';
  strPCopy(consulta,consultastr);
  writeln ('Executing query : ',Consulta,'...');
    if (mysql_query(sock,consulta) < 0) then
      begin
      Writeln (stderr,'Query failed ');
      writeln (stderr,mysql_error(sock));
      Halt(1);
      end;
----------

What is wrong?
Thanks in advance


--
-------
César Espinoza Soto
---------

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Insert into ... mysql

Henry Vermaak
2009/6/28 César Espinoza <[hidden email]>:

> Hi all  !!
>
> I did! I can now connect and query to mysql
>
> fpc 2.2.4, console, Macosx 10.5 leopard, Mac book Intel
>
> But I can't (may be I dont know :-( ) insert data in a table
> ------------
>  connect mysql  ... ok
>   select db ... ok
> .....
>   new(consulta);
>   consultastr:='INSERT INTO lugares (lugar) values (''Sala'')';
>   strPCopy(consulta,consultastr);

Is there enough space allocated for consulta to take
length(consultastr)+1?  Why don't you just use:

mysql_query(sock,PChar(consultastr))?

Henry
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Insert into ... mysql

John Coppens
In reply to this post by César Espinoza
On Sun, 28 Jun 2009 15:42:04 -0500
César Espinoza <[hidden email]> wrote:

> But I can't (may be I dont know :-( ) insert data in a table

If you can query, but not insert, there are a few things to check:

- Is the syntax of your insert correct? I mean, does column 'lugar' exist,
  and is it a varchar column, etc.?
- Are you allowed to insert? (Check the privileges for the person
  as who you log in. Insert, update, select, all have separate 'enables')
- What is the message returned by mysql_error?

John
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal