MCPcopy Create free account
hub / github.com/acl-dev/acl / db_create

Function db_create

lib_acl_cpp/samples/db/mysql_query/main.cpp:24–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 ")";
23
24static bool db_create(const char* dbaddr, const char* dbname,
25 const char* dbuser, const char* dbpass)
26{
27 acl::db_mysql db(dbaddr, "mysql", dbuser, dbpass);
28 if (db.open() == false)
29 {
30 printf("open %s@mysql error, dbuser: %s, dbpass: %s\r\n",
31 dbaddr, dbuser, dbpass);
32 return false;
33 }
34
35 acl::string sql;
36 sql.format("use mysql");
37 if (db.sql_update(sql.c_str()) == false)
38 {
39 printf("'%s' error: %s\r\n", sql.c_str(), db.get_error());
40 return false;
41 }
42 db.free_result();
43
44 sql.format("create database %s character set utf8;\r\n", dbname);
45 if (db.sql_update(sql.c_str()) == false)
46 {
47 printf("'%s' error: %s\r\n", sql.c_str(), db.get_error());
48 return false;
49 }
50 db.free_result();
51
52 // ����Mysql8.0 + ��ʹ�����淽ʽ
53 sql.format("grant CREATE,DROP,INSERT,DELETE,UPDATE,SELECT on %s.* to %s@localhost",
54 dbname, dbuser);
55
56 // Mysql8.0��ǰ�汾ʹ��
57 //sql.format("grant CREATE,DROP,INSERT,DELETE,UPDATE,SELECT on %s.* to %s",
58 // dbname, dbuser);
59
60 if (db.sql_update(sql.c_str()) == false)
61 {
62 printf("'%s' error: %s\r\n", sql.c_str(), db.get_error());
63 return false;
64 }
65 db.free_result();
66
67 sql = "flush privileges";
68 if (db.sql_update(sql.c_str()) == false)
69 {
70 printf("'%s' error: %s\r\n", sql.c_str(), db.get_error());
71 return false;
72 }
73 db.free_result();
74
75 printf("create db(%s) ok\r\n", dbname);
76 return true;
77}
78
79static bool tbl_create(const char* dbaddr, const char* dbname,
80 const char* dbuser, const char* dbpass)

Callers 1

mainFunction · 0.70

Calls 6

free_resultMethod · 0.80
openMethod · 0.45
formatMethod · 0.45
sql_updateMethod · 0.45
c_strMethod · 0.45
get_errorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…