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的更多相关文章

  1. 安装Access Database Engine后,提示未注册Microsoft.ACE.OLEDB.12.0

    未注册Microsoft.ACE.OLEDB.12.0 ,下载安装 Microsoft Access Database Engine:https://www.microsoft.com/en-us/d ...

  2. 错误1919,配置ODBC数据源MS Access Database时发生错误ODEC错误

    WIN7 64位旗舰版安装OFFICE2003 提示:“错误1919,配置ODBC数据源MS Access Database时发生错误ODEC错误” 在64位系统上,32位软件的注册表的信息不是直接在 ...

  3. Microsoft Access Database Engine 2010 Redistributable Download

    SQL Server 如需要导出类似Excel(*.xls.*.xlsx)格式的数据需要以来以下安装包 Microsoft Access 2010 数据库引擎可再发行程序包 此下载将安装一系列组件,帮 ...

  4. access database in a helper function ?

    <?php if(! function_exists('get_user_info')){ function get_user_info($field) { $ci = & get_in ...

  5. .Net语言 APP开发平台——Smobiler学习日志:基于Access数据库的Demo

    说明:该demo是基于Access数据库进行客户信息的新增.查看.编辑 新增客户信息和客户列表 Demo下载:https://github.com/comsmobiler/demo-videos  中 ...

  6. Access一些常用的SQL语句

    您可以将 Microsoft Office Access 2013 用作创建.修改数据库以及处理数据的工具,还可将 Office Access 2013 用作服务器数据库管理系统(如 Microsof ...

  7. 连接Access数据遇到的问题总览!

    由于要访问一个厂商的access数据,所以要写一个对于access的demo,相对于mysql.sqlserver来说,连接access花费了不少精力,现在将遇到的问题分享出来,以后大家遇到类似问题时 ...

  8. Delphi操作ACCESS技巧集

    1.DELPHI中操作access数据库(建立.mdb文件,压缩数据库)以下代码在WIN2K,D6,MDAC2.6下测试通过,编译好的程序在WIN98第二版无ACCESS环境下运行成功.//在之前us ...

  9. PowerDesigner生成Access数据库

    1.打开PowerDesigner,设置PowerDesigner的当前数据库为Access: 2.在PowerDesigner中新建表结构(物理模型): 3.PowerDesigner菜单中:Dat ...

随机推荐

  1. UVA - 10891 Game of Sum 区间DP

    题目连接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19461 Game of sum Description This ...

  2. 64位环境中使用SQL查询excel的方式解决

    --64位环境中使用SQL查询excel的方式 环境: OS:Windows Server 2008 R2 Enterprise MSSQL:Microsoft SQL Server 2008 R2 ...

  3. 如何应对Session丢失》》State Server

    Session丢失已经是一种习以为常的问题了,在自己也了解一些如何解决的问题,但是也一直没有机会去用,现在由于新的项目要在B/S下开发,所以不得不让我考虑Session的问题. 解决session丢失 ...

  4. WebView的写法

    public class MainActivity extends Activity { private WebView wv; @Override protected void onCreate(B ...

  5. DP URAL 1244 Gentlemen

    题目传送门 /* 题意:已知丢失若干卡片后剩余的总体积,并知道原来所有卡片的各自的体积,问丢失的卡片的id DP递推:首先从丢失的卡片的总体积考虑,dp[i] 代表体积为i的方案数,从dp[0] = ...

  6. Controlling z-order using the ZIndex Property

      The Composing a XAML Clip Art Scene posting showed how you could layer multiple drawing objects in ...

  7. BZOJ2388 : 旅行规划

    考虑分块,每块维护两个标记$ts,td$. 那么对于块中一个位置$i$,它的实际值为$i\times td+ts+v_i$. 修改的时候,对于整块,直接打标记,对于零散的暴力修改,然后重构凸壳,时间复 ...

  8. Google Code Jam 2010 Round 1C Problem B. Load Testing

    https://code.google.com/codejam/contest/619102/dashboard#s=p1&a=1 Problem Now that you have won ...

  9. JS倒计时代码

    第一种:精确到秒的javascript倒计时代码 HTML代码: <form name="form1"> <div align="center" ...

  10. [ZT] 几大酒店集团美国Co-Brand信用卡比较(三)如何选择最适合你的酒店联名信用卡

    原文地址: http://www.3798.com/archives/596.html 接着对我们这种不是某个酒店忠诚客户的用户选择卡片进行分析.首先要强调的是,我们比较的是信用卡项目本身,而不是酒店 ...