gcc conexion.c -o conexion -lodbc -std=gnu99
John Matthews wrote:Hi Fernando - sorry, can you explain what the problem is? You've shown some that code that appears to compile; doesn't it do what you want it to do?
Edit: ok, you've edited your post (again). Finished now?
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:Oh, man, I haven't heard of ODBC in years. I had to go check to see if it was even still a thing on Linux.
Went to the official website (https://docs.snowflake.com/en/user-guide/odbc-linux.html), read the docs and this is what I determined:
1. You have defined 2 DSNs in your odbc.ini, but only one of them is actually properly qualified (Mysql-odbc). The myodbc8a DSN isn't.
2. The Mysql-odbc DSN's Driver value isn't a Linux filesystem path to a driver. That is probably your main problem.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
FS: Please don't edit posts after they have been replied to; that causes no end of confusion about what question the answers are to. I have reverted the changes. Please show us any changes in a new post.John Matthews wrote:. . . ok, you've edited your post (again). . . .
gcc conexion.c -o conexion -lodbc -std=gnu99
profe@profe-VirtualBox:~/Downloads$ mysql -u root -s employees -p
Enter password:
mysql> select * from departments;
dept_no dept_name
d009 Customer Service
d005 Development
d002 Finance
d003 Human Resources
d001 Marketing
d004 Production
d006 Quality Management
d008 Research
d007 Sales
mysql>
profe@profe-VirtualBox:~/Downloads$ cat /etc/odbcinst.ini
[MySQL ODBC 8.0 Driver]
Driver=/usr/local/lib/libmyodbc8w.so
UsageCount=1
[MySQL ODBC 8.0]
Driver=/usr/local/lib/libmyodbc8a.so
UsageCount=1
profe@profe-VirtualBox:~/Downloads$ cat /etc/odbc.ini
[ODBC Data Sources]
myodbc8w = MyODBC 8.0 UNICODE Driver DSN
myodbc8a = MyODBC 8.0 ANSI Driver DSN
[myodbc8w]
Driver = /usr/local/lib/libmyodbc8w.so
Description = Connector/ODBC 8.0 UNICODE Driver DSN
SERVER = localhost
PORT =
USER = root
Password =
Database = test
OPTION = 3
SOCKET =
[myodbc8a]
Driver = /usr/local/lib/libmyodbc8a.so
Description = Connector/ODBC 8.0 ANSI Driver DSN
SERVER = localhost
PORT =
USER = root
Password =
Database = test
OPTION = 3
SOCKET =
profe@profe-VirtualBox:~/Downloads$ cat /etc/odbc.ini
[ODBC Data Sources]
myodbc8w = MyODBC 8.0 UNICODE Driver DSN
myodbc8a = MyODBC 8.0 ANSI Driver DSN
[myodbc8w]
Driver = /usr/local/lib/libmyodbc8w.so
Description = Connector/ODBC 8.0 UNICODE Driver DSN
SERVER = localhost
PORT =
USER = root
Password =
Database = test
OPTION = 3
SOCKET =
[myodbc8a]
Driver = /usr/local/lib/libmyodbc8a.so
Description = Connector/ODBC 8.0 ANSI Driver DSN
SERVER = localhost
PORT =
USER = root
Password =
Database = test
OPTION = 3
SOCKET =
profe@profe-VirtualBox:~/Downloads$ ./conexion
NO HA SIDO POSIBLE LA CONEXION
Campbell Ritchie wrote:Which textopok? Please always Quote Your Sources.
Tim Holloway wrote:Are you familiar with the basic syntax of ".ini" files?
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:OK. Well here's a good explanation of how .ini files work, and especially odbcinst.ini:
https://www.mankier.com/5/odbcinst.ini
The official manual page for odbc.ini itself can be found here:
https://www.mankier.com/5/odbc.ini
profe@profe-VirtualBox:~$ cat /etc/odbcinst.ini
[MySQL ODBC 8.0 Driver]
Driver=/usr/local/lib/libmyodbc8w.so
UsageCount=1
[MySQL ODBC 8.0]
Driver=/usr/local/lib/libmyodbc8a.so
UsageCount=1
profe@profe-VirtualBox:~$ cat /etc/odbc.ini
[MyDSN]
Description = Your MySQL database
Driver = MySQL ODBC 8.0 Unicode Driver
Server = 127.0.0.1
User = root
Password = ASIR2
Port = 3306
Database = employees
profe@profe-VirtualBox:~/Downloads$ ./conexion
ret= 0
ret= 0
ret= 0
ret= -1
SQL_NTS= -3
SQL_DRIVER_COMPLETE= 1
NO HA SIDO POSIBLE LA CONEXION
profe@profe-VirtualBox:~$ sudo apt-get install unixodbc unixodbc-dev libmyodbc
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package libmyodbc is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'libmyodbc' has no installation candidate
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:This might steer you towards a solution: https://www.datasunrise.com/professional-info/myodbc-on-ubuntu-16-04/
But I think it's time to step back and reflect on whether you've got an ideal approach. Do you actually need ODBC in particular, or is this a strictly MySQL app?
MySQL has a native API: https://dev.mysql.com/doc/c-api/8.0/en/ which while not portable the way ODBC is, is likely going to be easier to work with.
Likewise, is C the ideal language for the app. Many other Linux languages have database APIs that are are least somewhat cleaner than ODBC.
The gold standard, of course, when it comes to working with databases is Java, as JDBC is a true "write-once/run-anywhere" database interface. The downside being that you have to have a JVM installed, of course (though it's likely pre-installed on current Ubuntu distros).
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
What a stench! Central nervous system shutting down. Save yourself tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|