go access database demo
package main import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
"pricetable"
"strconv"
"strings"
)
const (
FILEPATH = "D:/test/pricetable/"
DB_USER = "xxxxtalog"
DB_PASSWORD = "xxxx27yeA"
DB_NAME = "xxxx7"
DB_HOST = "xxxxx.wwwww.com"
DB_PORT = ""
)
func main() { // for
callForavx6a() }
func callForavx6a() {
//Start
fmt.Println("# Execute Start !") //get model //ts := pricetable.GetTable_my_mec_ch_avx6a_prices()
ts := pricetable.GetTable_my_pmec_ch_avx6a_prices() //check file make sure file is new
pricetable.CheckfileExistAndDelete(FILEPATH, ts.TableName+".sql") /*
//get db connection
dbinfo := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable",
DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, DB_NAME)
db, err := sql.Open("postgres", dbinfo)
*/ //get db connection
dbinfo := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=disable",
DB_USER_N, DB_PASSWORD_N, DB_HOST_N, DB_PORT_N, DB_NAME_N)
db, err := sql.Open("postgres", dbinfo) pricetable.CheckErr(err)
defer db.Close() queryAvx6a(ts, db) //Print Execute finished info
fmt.Println("# Execute End !")
} func queryAvx6a(ts *pricetable.TableStruct, db *sql.DB) { tbname := ts.TableName
tbcolums := ts.TableColums fmt.Println("# Querying")
//fmt.Println(len(tablecolums))
for i, v := range tbcolums { //test sentence
if false {
fmt.Println(i, v)
} //combin query sql
//qstr := "SELECT \"model\",\"" + v + "\" FROM my_" + strings.TrimLeft(tbname, "my_")
qstr := "SELECT \"model\",\"" + v + "\" FROM " + tbname
fmt.Println(qstr)
rows, err := db.Query(qstr)
pricetable.CheckErr(err) for rows.Next() { var Model_id string
var val string err = rows.Scan(&Model_id, &val)
pricetable.CheckErr(err) if val == "N/A" {
continue
} var vv string f, err := strconv.ParseFloat(val, ) if err == nil {
if v == "CE21" {
vv = val
} else {
//do float round
vv = strconv.FormatFloat(pricetable.MyRound(f, ), 'f', , ) } } else {
vv = val
} //select * from price_constants
//filter fields
vv = pricetable.FilterString(vv) //("pid", "unit_name", "model", "refrigerant", "price_option", "y2013", "guid")
var pixstr string = "insert into " + strings.TrimLeft(tbname, "my_") + " (\"pid\", \"model\",\"price_option\", \"y2013\") VALUES (" contents := pixstr + "(select \"max\"(pid) from " + strings.TrimLeft(tbname, "my_") + ")" + " ,'" + strings.Trim(Model_id, " ") + "','" + strings.Trim(v, " ") + "','" + vv + "' );\n" //test print to console
//fmt.Println(contents) //writer to file
pricetable.Writertofile(contents, tbname+".sql", FILEPATH)
}
} } //======================================END==============
//pricetable
package pricetable type TableStruct struct {
TableName string
TableColums []string
} func GetTablea() *TableStruct {
ts := new(TableStruct)
ts.TableName = "Tablea"
ts.TableColums = []string{"acolumA", "acolumB"}
return ts
} func GetTableb() *TableStruct {
ts := new(TableStruct)
ts.TableName = "Tableb"
ts.TableColums = []string{"bcolumA", "bcolumB"}
return ts
} func GetTable_my_dbair2() *TableStruct {
ts := new(TableStruct)
ts.TableName = "my_dbair2"
ts.TableColums = []string{
"Basic 380-415/3ph/50Hz (AU )",
"Basic 460V/3ph/60Hz (Non-UL) (AR )",
"Drain Pan (Stainless Steel)",
"Discharge Plenum (Upflow only)",
"Steam Generating Humidifier",
"Hot Gas Bypass DX System Only",
"Liquid Line Solenoid Valve -DX Systems Only (50Hz)",
"Liquid Line Solenoid Valve -DX Systems Only (60Hz)",
"Panel Insulation (Insulflex)",
"Panel Insulation (Double Skin)",
"SKD (Complete built up unit, piping joints to be brazed by othe",
"Variable Frequency Drive (VFD) for Evaporator Blower Motor",
"UnderFloor Water Detector (PinHole Probe)",
"Smoke Detector",
"EEV (50Hz/60Hz)",
"BMS",
"Low Ambient Kit to 7°C/45F (at design ambient 95F)",
"Low Ambient Kit to 0°C/32F (at design ambient 95F)",
"Low Ambient Kit to -10°C/14F (at design ambient 95F)",
"Low Ambient Kit to 7°C/45F (at design ambient 105F)",
"Low Ambient Kit to 0°C/32F (at design ambient 105F)",
"Low Ambient Kit to -10°C/14F (at design ambient 105F)",
"Coil Fin - Hydrophilic",
"Coil Fin - Copper",
"Black Color Epoxy Powder Coating (In lieu of Std Beige Color) ",
} return ts
} //====================for ACPSB==================
func Gettable_my_6acpsb_p() *TableStruct {
ts := new(TableStruct)
ts.TableName = "my_6ACPSB_P"
ts.TableColums = []string{
//"unit_name",
//"model",
"basic-R22",
"basic-R407C",
"INS0.5",
"INS1",
"DWAL",
"LAC1",
"SV",
"HGBP",
"HWC",
"DOL1",
"DOL2",
"MII",
"CTLR",
"ADS-C",
"ADS-E",
"HYD-E",
"HYD-C",
"SPG",
"BotR/S",
"LIGHT",
"24VAC",
"SSB",
"FR",
} return ts
}
}
package pricetable import (
"fmt"
"math"
"os"
"strings"
) //func ContainMap(target string, ranges map[string]string) bool {
// var flag bool = false
// for k, _ := range ranges {
// if k == target {
// flag = true
// }
// }
// return flag
//} func ContainArray(target string, ranges []string) bool {
var flag bool = false
for _, v := range ranges {
if v == target {
flag = true
}
}
return flag
}
func FilterString(feild string) string { if strings.Index(feild, "CONSULT xxxxx") != - {
feild = "-88888"
}
if strings.Index(feild, "Contact factory") != - {
feild = "-88888"
}
if strings.Index(feild, "contact xxxx") != - {
feild = "-88888"
} if strings.Index(feild, "Consult factory") != - {
feild = "-88888"
}
if strings.Index(feild, "Consult xxx") != - {
feild = "-33333"
}
if strings.ToUpper(feild) == "STD" {
feild = "-66666"
}
if strings.ToUpper(feild) == "N/A" {
feild = "-77777"
} return feild
} func Exist(filename string) bool {
_, err := os.Stat(filename)
return err == nil || os.IsExist(err)
} func CheckfileExistAndDelete(path string, filename string) { if Exist(path + filename) { errs := os.Remove(path + filename)
if errs == nil {
fmt.Println("delete old file :" + path + filename + " success !")
} else {
fmt.Printf("Error: %s\n", errs)
}
} else {
fmt.Println("file:" + path + filename + " not exist,not need to delete !")
}
} func Writertofile(content string, filename string, path string) { fil, err := os.OpenFile(path+filename, os.O_RDWR|os.O_APPEND, )
//fmt.Println(path + filename)
if err != nil {
//fmt.Printf("Error: %s\n", err)
filnew, errnew := os.Create(filename)
if errnew != nil {
fmt.Printf("Error: %s\n", errnew)
filnew.Close()
return
} else {
fmt.Println(path + filename + " Create success !")
fil = filnew
} }
defer fil.Close()
fil.WriteString(content)
} func CheckErr(err error) {
if err != nil {
panic(err)
}
} func MyRound(f float64, n int) float64 {
pow10_n := math.Pow10(n)
return math.Trunc((f+0.5/pow10_n)*pow10_n) / pow10_n
} //func strings.TrimLeft(" !!! Achtung !!! ", "! ")
func Substr(str string, start, length int) string {
rs := []rune(str)
rl := len(rs)
end := if start < {
start = rl - + start
}
end = start + length if start > end {
start, end = end, start
} if start < {
start =
}
if start > rl {
start = rl
}
if end < {
end =
}
if end > rl {
end = rl
} return string(rs[start:end])
}
go access database demo的更多相关文章
- 安装Access Database Engine后,提示未注册Microsoft.ACE.OLEDB.12.0
未注册Microsoft.ACE.OLEDB.12.0 ,下载安装 Microsoft Access Database Engine:https://www.microsoft.com/en-us/d ...
- 错误1919,配置ODBC数据源MS Access Database时发生错误ODEC错误
WIN7 64位旗舰版安装OFFICE2003 提示:“错误1919,配置ODBC数据源MS Access Database时发生错误ODEC错误” 在64位系统上,32位软件的注册表的信息不是直接在 ...
- Microsoft Access Database Engine 2010 Redistributable Download
SQL Server 如需要导出类似Excel(*.xls.*.xlsx)格式的数据需要以来以下安装包 Microsoft Access 2010 数据库引擎可再发行程序包 此下载将安装一系列组件,帮 ...
- access database in a helper function ?
<?php if(! function_exists('get_user_info')){ function get_user_info($field) { $ci = & get_in ...
- .Net语言 APP开发平台——Smobiler学习日志:基于Access数据库的Demo
说明:该demo是基于Access数据库进行客户信息的新增.查看.编辑 新增客户信息和客户列表 Demo下载:https://github.com/comsmobiler/demo-videos 中 ...
- Access一些常用的SQL语句
您可以将 Microsoft Office Access 2013 用作创建.修改数据库以及处理数据的工具,还可将 Office Access 2013 用作服务器数据库管理系统(如 Microsof ...
- 连接Access数据遇到的问题总览!
由于要访问一个厂商的access数据,所以要写一个对于access的demo,相对于mysql.sqlserver来说,连接access花费了不少精力,现在将遇到的问题分享出来,以后大家遇到类似问题时 ...
- Delphi操作ACCESS技巧集
1.DELPHI中操作access数据库(建立.mdb文件,压缩数据库)以下代码在WIN2K,D6,MDAC2.6下测试通过,编译好的程序在WIN98第二版无ACCESS环境下运行成功.//在之前us ...
- PowerDesigner生成Access数据库
1.打开PowerDesigner,设置PowerDesigner的当前数据库为Access: 2.在PowerDesigner中新建表结构(物理模型): 3.PowerDesigner菜单中:Dat ...
随机推荐
- 电赛总结(二)——AD芯片总结之AD7715
一.特性参数 1.16位无失真AD转换器 2.增益可调,在1,2,32,128可切换. 3.数字地和模拟地分开,可以减少噪声. 4.具有较大的输出电流,有比较好的带载能力. 二.管脚排列 三.引脚功能 ...
- lr数据库参数化取数:The query result is empty and same is the parameter file问题原因
出现这个问题的原因: 是因为我们的查询结果存在中文 如果查询结果没有中文,显示正常 解决办法: 新建一个数据源: 重新再选择这个数据源,再次查询: 说明不是连接字符串的问题或者是mysql驱动的问题 ...
- elk是指logstash,elasticsearch,kibana三件套,这三件套可以组成日志分析和监控工具
Logstash是一个完全开源的工具,他可以对你的日志进行收集.分析,并将其存储供以后使用(如,搜索),您可以使用它.说到搜索,logstash带有一个web界面,搜索和展示所有日志.kibana 也 ...
- jquery.validate.js使用说明——后台添加用户邮箱功能:非空、不能重复、格式正确
重点内容为: jQuery验证控件jquery.validate.js使用说明+中文API[http://www.tuicool.com/articles/iABvI3] 简单教程可以参考[jQue ...
- 模拟 POJ 1068 Parencodings
题目地址:http://poj.org/problem?id=1068 /* 题意:给出每个右括号前的左括号总数(P序列),输出每对括号里的(包括自身)右括号总数(W序列) 模拟题:无算法,s数组把左 ...
- MapReduce的输入输出格式
默认的mapper是IdentityMapper,默认的reducer是IdentityReducer,它们将输入的键和值原封不动地写到输出中. 默认的partitioner是HashPartitin ...
- POJ3162 Walking Race(树形DP+尺取法+单调队列)
题目大概是给一棵n个结点边带权的树,记结点i到其他结点最远距离为d[i],问d数组构成的这个序列中满足其中最大值与最小值的差不超过m的连续子序列最长是多长. 各个结点到其他结点的最远距离可以用树形DP ...
- HDU2825 Wireless Password(AC自动机+状压DP)
题目问长度n至少包含k个咒语的字符串有多少个.也是比较入门的题.. dp[i][j][S]表示长度i(在自动机上转移k步)且后缀状态为自动机上第j个结点且当前包含咒语集合为S的方案数 dp[0][0] ...
- ! cocos2d sprintf的问题
char dong[100]; sprintf(dong,"%s","dongshen"); CCLOG(dong); 以上正确 char dong[100]; ...
- cocos2d 创建精灵图
// 在init这个函数当中做一些初始化的事情 bool HelloWorld::init() { ////////////////////////////// // 先构造父级对象 if ( !CC ...