func TestDate(t *testing.T) { myConnect(t, true, 0) query("drop table D") // Drop test table if exists checkResult(t, query("create table D (id int, dd date, dt datetime, tt time)"), cmdOK(0, false, true), ) dd := "2011-12-13" dt := "2010-12-12 11:24:00" tt := -mysql.Time((124*3600+4*3600+3*60+2)*1e9 + 1) ins, err := my.Prepare("insert D values (?, ?, ?, ?)") checkErr(t, err, nil) sel, err := my.Prepare("select id, tt from D where dd <= ? && dt <= ?") checkErr(t, err, nil) _, err = ins.Run(1, dd, dt, tt) checkErr(t, err, nil) rows, _, err := sel.Exec(mysql.StrToDatetime(dd), mysql.StrToDate(dd)) checkErr(t, err, nil) if rows == nil { t.Fatal("nil result") } if rows[0].Int(0) != 1 { t.Fatal("Bad id", rows[0].Int(1)) } if rows[0][1].(mysql.Time) != tt+1 { t.Fatal("Bad tt", rows[0][1].(mysql.Time)) } checkResult(t, query("drop table D"), cmdOK(0, false, true)) myClose(t) }
import ( "bytes" "github.com/ziutek/mymysql/mysql" "math" "reflect" "testing" ) var ( Bytes = []byte("Ala ma Kota!") String = "ssss" //"A kot ma AlÄ™!" blob = mysql.Blob{1, 2, 3} dateT = mysql.Datetime{Year: 2010, Month: 12, Day: 30, Hour: 17, Minute: 21} tstamp = mysql.Timestamp{Year: 2001, Month: 2, Day: 3, Hour: 7, Minute: 2} date = mysql.Date{Year: 2011, Month: 2, Day: 3} tim = -mysql.Time((5*24*3600+4*3600+3*60+2)*1e9 + 1) pBytes *[]byte pString *string pBlob *mysql.Blob pDateT *mysql.Datetime pTstamp *mysql.Timestamp pDate *mysql.Date pTim *mysql.Time raw = mysql.Raw{MYSQL_TYPE_INT24, &[]byte{3, 2, 1}} Int8 = int8(1) Uint8 = uint8(2) Int16 = int16(3) Uint16 = uint16(4)