You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
828 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package CommonDao
import (
"dsAutoCode/Utils/ConfigUtil"
"dsAutoCode/Utils/DbUtil"
)
var db = DbUtil.Engine
/**
功能:获取指定表格的主键
作者:黄海
时间2020-05-30
*/
func GetTablePk(tableName string) (string,string) {
sql := "select column_name from information_schema.`key_column_usage` where table_name='" + tableName + "' and constraint_name='primary' and constraint_schema='" + ConfigUtil.WorkingDataBase + "'"
list, _ := db.SQL(sql).Query().List()
pk := list[0]["column_name"].(string)
//主键的数据类型
sql = "select data_type from information_schema.columns where table_name = '" + tableName + "' and table_schema = '" + ConfigUtil.WorkingDataBase + "' and column_name='"+pk+"'"
list, _ = db.SQL(sql).Query().List()
dataType :=list[0]["data_type"].(string)
return pk, dataType
}