Closed vorlif closed 7 years ago
Are you planning to support SQL Time in the near future?
You obviously have some example of ODBC driver returning SQL_TYPE_TIME to github.com/alexbrainman/odbc. How can I see it too? I have never seen SQL_TYPE_TIME in my environments. What database do you use? What driver? What OS?
Thank you
Alex
Also maybe you have small program to demonstrate that.
Alex
Hi, thanks for the quick response.
We use a very old database called Pervasive. Unfortunately this is proprietary and no longer supported. Therefore you probably can not test directly with it. :-/ Sorry.
But I could create the same problem with a MySQL Database over ODBC.
Here my Example:
Schema:
mysql> show create table testdb.example;
+---------+----------------------------------------------+
| Table | Create Table |
+---------+----------------------------------------------+
| example | CREATE TABLE `example` (
`id` int(6) unsigned NOT NULL AUTO_INCREMENT,
`time` time DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 |
+---------+----------------------------------------------+
package main
import (
"log"
"database/sql"
"time"
_ "github.com/alexbrainman/odbc"
)
func main() {
// Connect
db, err := sql.Open("odbc", "DSN=testdb;Uid=root;Pwd=test1234;")
if err != nil {
log.Fatal(err)
}
// Insert a example
stmt, err := db.Prepare("INSERT INTO example(time) VALUES(?)")
if err != nil {
log.Fatal(err)
}
_, err = stmt.Exec(time.Now())
if err != nil {
log.Fatal(err)
}
var (
id int
dbTime time.Time
)
// Try to fetch the example
rows, err := db.Query("select id, time from example where id = ?", 1)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(&id, &dbTime)
if err != nil {
log.Fatal(err)
}
log.Println(id, dbTime)
}
}
Output:
2017/07/29 14:57:38 unsupported column type 92
exit status 1
Florian
OS: Windows 7, 8, 10 Database: PervasiveSQL, MySQL
What do you mean with drivers? ODBC-Driver? I use Windows built in ODBC driver.
db, err := sql.Open("odbc", "DSN=testdb;Uid=root;Pwd=test1234;")
I do not have DSN=testdb configured on my computer. How do I create that?
What do you mean with drivers? ODBC-Driver? I use Windows built in ODBC driver.
I have Windows 10, but it does not come with "builtin in" mysql ODBC driver. Where do I get that?
Thank you.
Alex
Hello Alex,
you can download the mysql ODBC driver from here After you've installed it would appear the driver.
The database I had created. You must open the MySQL Cli (or a other command line from where you can use mysql) and then enter the following commands:
mysql> create database testdb;
mysql> create table testdb.example(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, time TIME);
If you then create an ODBC connection, the script from above should run.
Thank you for your effort. Florian
@Vorlif could you try pull request #94 ? Thank you.
Alex
Hello Alex,
a thousand thanks for your trouble and the work. It works great.
The only thing I noticed is that you use day 0. The result is a time with format -0001-11-30 09:32:04 +0100 CET
. This format is not supported by the json package. I think the golang default here is day, month and year 1?
But I can change this manually in my program.
Thanks again. You can close the issue if you want. I'm happy.
The only thing I noticed is that you use day 0. The result is a time with format -0001-11-30 09:32:04 +0100 CET. This format is not supported by the json package. I think the golang default here is day, month and year 1?
I agree. Changed.
Alex
Hi, thank you for the gread package! :)
Are you planning to support SQL Time in the near future?