Ejemplo n.º 1
0
func init_xml() {
	conStr := "personnes.xml"
	conn := gouda.OpenXML(conStr).(*gouda.XMLConnector)
	table := conn.CreateTable("personne")
	table.AddAttribute("nom", gouda.StringKind)
	table.AddAttribute("age", gouda.IntKind)
	table.Insert(map[string]gouda.Value{"id": gouda.SysInt(1).Value(), "nom": gouda.SysString("toto").Value(), "age": gouda.SysInt(13).Value()})
	table.Insert(map[string]gouda.Value{"id": gouda.SysInt(2).Value(), "nom": gouda.SysString("titi").Value(), "age": gouda.SysInt(0).Value()})
	table = conn.CreateTable("cars")
	table.AddAttribute("plate", gouda.StringKind)
	table.AddAttribute("model", gouda.StringKind)
	table.AddAttribute("owner_id", gouda.IntKind)
	table.Insert(map[string]gouda.Value{"id": gouda.SysInt(1).Value(), "plate": gouda.SysString("123ABC12").Value(), "model": gouda.SysString("Renault").Value(), "owner_id": gouda.SysInt(1).Value()})
	conn.Close()
	conn2 := gouda.OpenXML(conStr)
	gouda.GetConnectionStore().RegisterConnection(&conn2)

}
Ejemplo n.º 2
0
func init_mysql() {
	r, w, err := os.Pipe()
	if err != nil {
		panic("%v", err)
	}

	fmt.Print("Initializing DB... ")
	pid, _ := os.ForkExec("/usr/bin/mysql", []string{"/usr/bin/mysql", "test_db"}, os.Environ(), "/versatile", []*os.File{r, os.Stdout, os.Stderr})
	//	fmt.Fprintln(w,"show tables;");
	fmt.Fprintln(w, "DROP TABLE personne;")
	fmt.Fprintln(w, "DROP TABLE cars;")
	fmt.Fprintln(w, "CREATE TABLE `personne` ( `id` int(11) NOT NULL auto_increment, `nom` varchar(255) default NULL,  age int(3) default NULL,   PRIMARY KEY  (`id`)  );")
	fmt.Fprintln(w, "INSERT INTO `personne` VALUES (1,'toto',23);")
	fmt.Fprintln(w, "INSERT INTO `personne` VALUES (2,'titi',NULL);")
	fmt.Fprintln(w, "CREATE TABLE `cars` ( `id` int(11) NOT NULL auto_increment, `plate` varchar(255) default NULL,   `model` varchar(255) default NULL, owner_id int(11) default NULL,   PRIMARY KEY  (`id`)  );")
	fmt.Fprintln(w, "INSERT INTO `cars` VALUES (1,'123ABC12','Renault',1);")
	fmt.Fprintln(w, "INSERT INTO `cars` VALUES (2,'123CBA12','Traban',1);")
	w.Close()
	os.Wait(pid, 0)
	fmt.Println("Finished!")

	conn := gouda.OpenMysql("mysql://root:@localhost:3306/test_db")
	gouda.GetConnectionStore().RegisterConnection(&conn)
}
Ejemplo n.º 3
0
func need_connection() gouda.Connection {
	conn := gouda.OpenMysql("mysql://root:@localhost:3306/test_db")
	gouda.GetConnectionStore().RegisterConnection(&conn)
	return conn
}