2018-12-10 06:06:37 +00:00
|
|
|
package logdb
|
|
|
|
|
|
|
|
import (
|
2018-12-10 08:52:46 +00:00
|
|
|
"log"
|
2018-12-10 06:06:37 +00:00
|
|
|
"testing"
|
2018-12-10 09:13:22 +00:00
|
|
|
"time"
|
2018-12-10 06:06:37 +00:00
|
|
|
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
)
|
|
|
|
|
|
|
|
// charset: utf8mb4
|
|
|
|
// db: test_log
|
|
|
|
// hosts: [192.168.6.101, 192.168.6.102, 192.168.6.103, 192.168.6.104, 192.168.6.105]
|
|
|
|
// password: ag-spider-log
|
|
|
|
// port: 4000
|
|
|
|
// user: spider
|
|
|
|
|
2018-12-10 09:13:22 +00:00
|
|
|
type ADStore struct {
|
|
|
|
uid string
|
|
|
|
spider_id int
|
|
|
|
device string
|
|
|
|
platform string
|
|
|
|
channel int
|
|
|
|
media int
|
|
|
|
area_cc string
|
|
|
|
catch_account_id int
|
|
|
|
section_id string
|
|
|
|
response string
|
|
|
|
status int
|
|
|
|
error_msg string
|
|
|
|
ext string
|
|
|
|
priority int
|
|
|
|
ts_crawl time.Time
|
|
|
|
ts_update time.Time
|
|
|
|
}
|
2018-12-10 06:10:24 +00:00
|
|
|
|
2018-12-10 09:13:22 +00:00
|
|
|
func TestSelect(t *testing.T) {
|
|
|
|
log.SetFlags(log.Llongfile)
|
2018-12-10 06:06:37 +00:00
|
|
|
logdb := NewLogDB("logdb.yaml")
|
|
|
|
logdb.Connect()
|
2018-12-10 06:10:24 +00:00
|
|
|
t.Error(logdb)
|
2018-12-10 09:21:28 +00:00
|
|
|
rows := logdb.Select("select uid, spider_id, device, platform, response from log_spider limit 10;")
|
2018-12-10 08:52:46 +00:00
|
|
|
log.Println(rows)
|
2018-12-10 09:13:22 +00:00
|
|
|
|
|
|
|
var l []ADStore
|
|
|
|
for rows.Next() {
|
|
|
|
ad := ADStore{}
|
2018-12-10 09:21:28 +00:00
|
|
|
rows.Scan(&ad.uid, &ad.spider_id, &ad.device, &ad.platform, &ad.response)
|
2018-12-10 09:13:22 +00:00
|
|
|
l = append(l, ad)
|
|
|
|
}
|
|
|
|
log.Println(len(l))
|
2018-12-10 06:06:37 +00:00
|
|
|
}
|