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 ...
随机推荐
- TFS2012团队管理基本配置及基础使用方法
本文介绍如何在VS2012中使用微软提供的TFS2012服务器进行团队协作开发,免费默认只支持5用户,主要分为两大步服务器配置跟客户端配置. 转载请标注:http://www.kwstu.com/Ar ...
- 自爽:DOTNET 笔试题
2-3年经验估计,求轻拍~ 在多态中,经常用到virtual和abstract,请问区别是什么?并描述其适用场景. 请描述Action,Action<T>,Func<T>,Fu ...
- EntityFramework 6.0< Code First > 连接 Mysql数据库
网上有很多关于用EntityFrame来连接Mysql数据库的教程,可是很多并不靠谱,转载的太多了.找了很久,总算是配置好了,现在分享一下. 一,安装: 1.开发环境: VS2013与EF6 ...
- ural 1283. Dwarf
1283. Dwarf Time limit: 1.0 secondMemory limit: 64 MB Venus dwarfs are rather unpleasant creatures: ...
- TC SRM 584 DIV 2
第一次在DIV2 AK了. 250水题. 500,FLoyd搞出所有边的最短路,然后找最短路,中最长的,如果有不连通的边返回-1 1000,组合DP,各种慌乱,在最后1分钟时,交上了,感觉很棒,最后还 ...
- 在openGL中绘制图形
点的绘制.: glVertex*():星号表示函数要有后缀 该函数 需要放在glBegin函数和glEnd函数之间,glBegin函数的向量指定绘制图元的类型,而glEnd函数没有参数,例如: glB ...
- Servlet 编程 简单流程处理(重定向)
流程(来自jiekexueyuan) servlet sucess.jsp error.asp同理 运行结果:
- nodejs安装和环境搭建
环境下载 根据系统类型,系统位数选择需要的版本下载.下载地址:https://nodejs.org/en/download/ msi:开发环境,包含运行环境,开发文档等,所以我们下载.msi. exe ...
- SAE saestorage.class.php文件的封装代码
Source for file saestorage.class.php Documentation is available at saestorage.class.php <?php /** ...
- Redis 笔记与总结2 String 类型和 Hash 类型
Linux 版本信息: cat /etc/issue 或cat /etc/redhat-release(Linux查看版本当前操作系统发行版信息) CentOS release 6.6 (Final) ...