Created
May 25, 2018 22:55
-
-
Save triztian/fe6feba9d4266ac962b37253a91281fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"log" | |
"time" | |
_ "github.com/alexbrainman/odbc" | |
) | |
type userRecord struct { | |
ID string | |
Nombre string | |
FechaVen time.Time | |
FechaReg time.Time | |
} | |
func main() { | |
const ( | |
host = "" | |
userLogin = "" | |
passLogin = "" | |
) | |
db, err := sql.Open("odbc", "DSN="+host) | |
if err != nil { | |
log.Fatal("Could not connect to db:", err) | |
} | |
if err = db.Ping(); err != nil { | |
log.Fatal("got an error:", err) | |
} | |
/*SELECT*/ | |
rows, err := db.Query(` | |
SELECT | |
su.coduser AS id, | |
TRIM(su.nomuser) AS user, | |
s.fchven AS fch_ven, | |
s.fecreg AS fch_registro | |
FROM | |
suser su JOIN sinfo s ON s.coduser = su.coduser | |
WHERE | |
su.nomuser=? AND su.pass=?`, | |
userLogin, passLogin) | |
for rows.Next() { | |
user := &userRecord{} | |
// Scan the result into the column pointers... | |
if err := rows.Scan(&user.ID, &user.Nombre, &user.FechaVen, &user.FechaReg); err != nil { | |
log.Fatal(err) | |
} | |
// This will print each user | |
log.Println(user) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment