Exemplo n.º 1
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)
}
Exemplo n.º 2
0
func need_connection() gouda.Connection {
	conn := gouda.OpenMysql("mysql://root:@localhost:3306/test_db")
	gouda.GetConnectionStore().RegisterConnection(&conn)
	return conn
}