Beispiel #1
0
// GetDSN returns a (command-line defined) connection string
func GetDSN() string {
	if !flag.Parsed() {
		flag.Parse()
		if *fDsn == "" {
			*fDsn = os.Getenv("DSN")
		}
	}

	var user, passw, sid string
	if !(fDsn == nil || *fDsn == "") {
		user, passw, sid = oracle.SplitDSN(*fDsn)
		//log.Printf("user=%q passw=%q sid=%q", user, passw, sid)
	}
	if user == "" && fUsername != nil && *fUsername != "" {
		user = *fUsername
	}
	if passw == "" && fPassword != nil && *fPassword != "" {
		passw = *fPassword
	}
	if sid == "" {
		if fSid != nil && *fSid != "" {
			sid = *fSid
		} else {
			sid = oracle.MakeDSN(*fHost, *fPort, "", *fServiceName)
		}
	}
	return user + "/" + passw + "@" + sid
}
Beispiel #2
0
func InitOracle() (ITransactionManager, *sql.DB) {
	logger.Infof("******* Using Oracle *******\n")

	common.RAW_SQL = "SELECT name FROM book WHERE name LIKE ?"

	translator := trx.NewOracleTranslator()
	translator.RegisterTranslation(
		common.TOKEN_SECONDSDIFF,
		func(dmlType DmlType, token Tokener, tx Translator) string {
			m := token.GetMembers()
			return fmt.Sprintf(
				"(SYSDATE - ( %s - %s) - SYSDATE)*86400",
				tx.Translate(dmlType, m[1]),
				tx.Translate(dmlType, m[0]),
			)
		},
	)

	//var sid = oracle.MakeDSN("oracleserver", 1521, "", "XE")
	var sid = oracle.MakeDSN("192.168.56.101", 1521, "", "XE")
	return common.InitDB("goracle", "gosql/gosql@"+sid, translator)
}