Go & SQLite on Windows
一般golang使用的sqlite驱动包都是github.com/mattn/go-sqlite3,但是官方并没有直接支持windows平台的编译,因为windows平台编译默认需要gcc支持
其实解决办法很简单,只需要在windows平台下安装gcc即可正常使用。
编译错误如下:
go get github.com/mattn/go-sqlite3
# github.com/mattn/go-sqlite3
exec: "gcc": executable file not found in %PATH%
下面说明如何解决:
1. 下载GCC http://tdm-gcc.tdragon.net/download
2. 安装GCC






3. 打开MinGW Command Prompt 安装sqlite3
go get github.com/mattn/go-sqlite3

4. 安装好就可以测试程序了
package main import (
"database/sql"
"fmt" _ "github.com/mattn/go-sqlite3"
) func main() {
//1. Open connection db, err := sql.Open("sqlite3", ":memory:")
checkErr(err)
defer db.Close() //2. fail-fast if can't connect to DB checkErr(db.Ping()) //3. create table _, err = db.Exec("create table USER (ID integer PRIMARY KEY, NAME string not null); delete from USER;")
checkErr(err) //4. insert data //4.1 Begin transaction
tx, err := db.Begin()
checkErr(err) //4.2 Prepare insert stmt.
stmt, err := tx.Prepare("insert into USER(ID, NAME) values(?, ?)")
checkErr(err)
defer stmt.Close() for i := ; i < ; i++ {
_, err = stmt.Exec(i, fmt.Sprint("user-", i))
checkErr(err)
} //4.3 Commit transaction
tx.Commit() //5. Query data rows, err := db.Query("select * from USER")
checkErr(err)
defer rows.Close() //5.1 Iterate through result set
for rows.Next() {
var name string
var id int
err := rows.Scan(&id, &name)
checkErr(err)
fmt.Printf("id=%d, name=%s\n", id, name)
} //5.2 check error, if any, that were encountered during iteration
err = rows.Err()
checkErr(err)
} func checkErr(err error, args ...string) {
if err != nil {
fmt.Println("Error")
fmt.Println("%q: %s", err, args)
}
}
Go & SQLite on Windows的更多相关文章
- SQLite.Net-PCLUSING SQLITE IN WINDOWS 10 UNIVERSAL APPS
USING SQLITE IN WINDOWS 10 UNIVERSAL APPS 1.下载SQLite VSIX package并安装 http://sqlite.org/download.html ...
- SQLite in Windows Store Apps
Using SQLite in Windows Store Apps : https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Using-SQL ...
- SQLite 在Windows Server 2008 R2 部署问题FAQ汇总[轉]
轉自:http://www.steveluo.name/sqlite-windows-server-2008-r2-deploy-faq/ 今天花了一天的时间研究了一下SQLite,以取代一些轻量级项 ...
- Sqlite在Windows、Linux 和 Mac OS X 上的安装过程
一:在 Windows 上安装 SQLite 1,下载 请访问SQLite下载页面http://www.sqlite.org/download.html,从Windows 区下载预编译的二进制文件.需 ...
- [Sqlite] --> Sqlite于Windows、Linux 和 Mac OS X 在安装过程
一个:于 Windows 安装 SQLite 1,下载 请訪问SQLite下载页面http://www.sqlite.org/download.html.从Windows 区下载预编译的二进制文件. ...
- Windows Phone 九、SQLite数据库
使用SQLite数据库 安装 SQLite for Windows Phone 8.1 插件新建 Windows Phone 8.1 项目添加 SQLite for Windows Phone 8.1 ...
- How to get SQLite work on windows phone 8
1.Install SQLite for Windows Phone SDKC:\Program Files (x86)\Microsoft SDKs\Windows Phone\v8.0\Exten ...
- 在Windows Phone 8.1中使用Sqlite数据库
前言 我的工作目前不涉及到Windows phone的开发,但是业余时间也开发过几款app.以前由于各种条件的限制,只接触到WP8.0设备的app开发. 最近几个月开始将WP8的应用迁移到WP8.1, ...
- Using SQLite database in your Windows 10 apps
MVP可以在channel 9上传视频了,所以准备做个英文视频传上去分享给大家,本文做稿子. Hello everyone, As we all know, SQLite is a great and ...
随机推荐
- php分页插件
前台调用样式<?php include_once('page.class.php');?><link rel="stylesheet" type="te ...
- Mac 全局变量 ~/.bash_profile 文件不存在的问题
不存在就新建呗~ $ cd ~/ $ touch .bash_profile $ open -e .bash_profile 然后输入以下内容 # set color的部分是配置iterm2的字体颜色 ...
- shared-service.ts
shared-service.ts import { Observable } from 'rxjs/Observable'; import { Injectable } from '@angular ...
- MVC & Entity Framework(2)- controller、Models单独DLL
继上一篇MVC & Entity Framework(1)- 开发环境之后,已经很久没更新了.接下来记录一下怎么把MVC中的controller单独拆为一个类库,然后在web项目中引用.另外, ...
- mysql之内存表
一.引言 昨天下午老大让我查资料看一下mysql的内存表在主从备份中是否能被复制,我还没听说过内存表呢,于是上网查资料,记录一下,以便查阅.学习 二.进展 参考: http://www.cnblogs ...
- Unix系统编程()文件空洞
如果程序的文件偏移量已然跨越了文件结尾,然后再执行IO操作,将会发生什么情况? read调用将会返回0,表示文件结尾.令人惊讶的是,write函数可以在文件结尾后的任意位置写入数据. 从文件结尾后到新 ...
- BZOJ2820 YY的GCD 莫比乌斯+系数前缀和
/** 题目:BZOJ2820 YY的GCD 链接:http://www.cogs.pro/cogs/problem/problem.php?pid=2165 题意:神犇YY虐完数论后给傻×kAc出了 ...
- python判断字符串是否为空的方法s.strip()=='' if not s.strip():
python 判断字符串是否为空用什么方法? 复制代码 s=' ' if s.strip()=='': print 's is null' 或者 if not s.strip(): p ...
- redis info命令中各个参数的含义
Redis 性能调优相关笔记 2016年09月25日 15:42:04 WenCoding 阅读数:4844更多 个人分类: Redis数据库 info可以使用info [类别]输出指定类别内容i ...
- ifconfig配置网络时,出现“SIOCSIFADDR: No such device”
最近刚学习linux,参考教学视频,试着使用ifconfig命令来设置网卡参数,命令为“ifconfig eth0 192.168.11.2”. 但结果显示“SIOCSIFADDR: No such ...