// Get the table data
func dumpTableData(w io.Writer, db mysql.Conn, table string) {
	fmt.Fprintf(w, "\n--\n-- Dumping data for table `%s`\n--\n\n", table)

	rowCnt, _, err := db.QueryFirst(getSelectCountQueryFor(db, table))
	checkError(err)
	if rowCnt.Int(0) == 0 {
		fmt.Fprintf(w, "--\n-- Empty table\n--\n\n")
		return
	} else {
		fmt.Fprintf(w, "--\n-- %d rows\n--\n\n", rowCnt.Int(0))
	}

	fmt.Fprintf(w, "LOCK TABLES `%s` WRITE;\n", table)
	query := fmt.Sprintf("INSERT INTO `%s` VALUES", table)
	rows := make([]string, 0)

	res, err := db.Start(getSelectQueryFor(db, table))
	checkError(err)
	row := res.MakeRow()

	for {
		err = res.ScanRow(row)
		if err == io.EOF {
			break
		}
		checkError(err)

		vals := make([]string, 0)
		for k, col := range row {
			val := "NULL"
			if col != nil {
				val = fmt.Sprintf("'%s'", db.EscapeString(row.Str(k)))
			}
			vals = append(vals, val)
		}

		rows = append(rows, fmt.Sprintf("( %s )", strings.Join(vals, ", ")))
		if len(rows) >= 100 {
			fmt.Fprintf(w, "%s\n%s;\n", query, strings.Join(rows, ",\n"))
			rows = make([]string, 0)
		}
	}

	if len(rows) > 0 {
		fmt.Fprintf(w, "%s\n%s;\n", query, strings.Join(rows, ",\n"))
	}

	fmt.Fprintf(w, "\nUNLOCK TABLES;\n")
}
示例#2
0
func (this *DataModule) AccountloginToo(param *acc.LoginPlayer_MA, itbid int32, conn mysql.Conn) *AccParams {
	str := fmt.Sprintf(`set @iisfcm = %d`, 1)
	res, err := conn.Start(str)
	if err != nil {
		fmt.Println("存储过程调用失败", err.Error())
	}

	str = fmt.Sprintf(`set @iserverid = %d`, 0)
	res, err = conn.Start(str)
	if err != nil {
		fmt.Println("存储过程调用失败", err.Error())
	}

	str = fmt.Sprintf(`call mfxy_accountlogin(%d,'%s','%s','%s','%s',@iserverid,%d,%d,%d,@iisfcm,@ifcmtime,@iaccid,@igmlevel,@igamepoints,@szprotectques,@szprotectansw,@iretval)`,
		itbid, *param.SzAccount, *param.SzPassword, *param.SzIp, "haha", *param.ProductId, *param.PlatformId, *param.LoginType)
	fmt.Println(str)
	res, err = conn.Start(str)
	if err != nil {
		fmt.Println("存储过程调用失败", err.Error())
	}

	str = fmt.Sprintf(`select @iserverid,@iisfcm,@ifcmtime,@iaccid,@igmlevel,@igamepoints,@szprotectques,@szprotectansw,@iretval`)
	fmt.Println(str)
	res, err = conn.Start(str)
	if err != nil {
		fmt.Println("存储过程调用失败", err.Error())
	}

	row, _ := res.GetRow()

	repParams := new(AccParams)
	repParams.Serverid = uint64(row.Int(0))
	repParams.Isfcm = uint32(row.Int(1))
	repParams.Ifcmtime = uint64(row.Int64(2))
	repParams.Accid = uint64(row.Int64(3))
	repParams.Gmlevel = uint32(row.Int(4))
	repParams.Points = uint64(row.Int(5))
	repParams.Productid = uint64(row.Int64(6))
	repParams.Protectansw = row.Str(7)
	repParams.Iretval = int32(row.Int(8))
	fmt.Println("datamodul end")
	return repParams
}