Windows problem with database/sql or cznic/ql...

blov · · 897 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m having this weird problem with the lock files on Windows. Keep in mind that this is happening <strong>only</strong> on windows. I have zero problems with non-clearing lockfiles when I deploy to my linux server and have to restart the program. </p> <p>Specs:</p> <ul> <li>Windows 7 64 bit</li> <li>go1.4.2 32bit</li> <li>git bash</li> </ul> <p>What happens is that the lockfile doesn&#39;t get emptied after a transaction is commited nor after the parent function of db.QueryRow returns.</p> <p>For example the route:</p> <pre><code>func SubmitPost(w http.ResponseWriter, r *http.Request, p httprouter.Params) { var tmp string title := &#34;test&#34; url := &#34;test&#34; err = db.QueryRow(&#34;select title from posts where url==$1&#34;, title).Scan(&amp;tmp) tx, _ := db.Begin() // if the record is in the database, delete it if err == nil { _, err2 := tx.Exec(&#34;delete from posts where title==$1;&#34;, title) if err2 != nil { log.Println(&#34;delete: &#34;, err2) } } _, err = tx.Exec(&#34;insert into posts values ($1, $2, $3, $4);&#34;, url, title, []byte(&#34;z&#34;), time.now()) if err != nil { log.Println(&#34;query: &#34;, err) } if err = tx.Commit(); err != nil { log.Println(&#34;commit: &#34;, err) } } </code></pre> <p>Even if I just do the db.QueryRow, I still have the lockfile after my server exits. This is the initialization of my db</p> <pre><code>package main import ( &#34;database/sql&#34; &#34;encoding/json&#34; &#34;github.com/julienschmidt/httprouter&#34; &#34;io/ioutil&#34; &#34;log&#34; &#34;net/http&#34; &#34;time&#34; ) type Post struct { Url string Title string Content string Date time.Time } type Config struct { Git string Port string Reload string Submit string Deploy string } var db *sql.DB var config Config func main() { var err error db, err = sql.Open(&#34;ql&#34;, &#34;ql.db&#34;) defer db.Close() if err != nil { log.Fatal(err) } router := httprouter.New() router.GET(config.Submit, SubmitPost) router.NotFound = Error404 log.Fatal(http.ListenAndServe(&#34;:8080&#34;, router)) } </code></pre> <p>Originally I was getting the lockfile not clearing because I wasn&#39;t deferring the database close. Now I am having the problem anytime a transaction is created. Is this something I should create an issue for on the tracker or am I crazy and missing something?</p> <hr/>**评论:**<br/><br/>cryp7ix: <pre><p>Can you please put together a minimal reproduction case and post it to the github issue page of cznic/ql?</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

897 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传