Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op:对sql接口进行修改 #7

Merged
merged 22 commits into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
838b741
commit
nomanker Apr 6, 2021
40b16e2
完成前端发送请求后端返回json功能,待修复bug
ggssh Apr 6, 2021
33a7c83
完成前端发送请求后端返回json功能,待修复bug
ggssh Apr 7, 2021
fa85dd7
完成前端发送请求后端返回json功能,待修复bug
ggssh Apr 7, 2021
71bc216
fixed:查询结果为空出现异常,resultset跳过第一行数据,解决已知内存泄漏
ggssh Apr 7, 2021
2bfe883
store
ggssh Apr 11, 2021
8221be1
完成sql连接放到main函数执行,ksql函数加前缀,将每次查询结果集内存回收
ggssh Apr 12, 2021
997f06c
完成sql连接放到main函数执行,ksql函数加前缀,将每次查询结果集内存回收
ggssh Apr 18, 2021
4dceef6
完成sql连接放到main函数执行,ksql函数加前缀,将每次查询结果集内存回收
ggssh Apr 21, 2021
79ff9c5
修复函数指针
nomanker Apr 21, 2021
391c580
Merge branch 'nomanker' of https://github.com/Kingtous/Sysy2020-llvm-…
ggssh Apr 21, 2021
e314add
opt:删掉CGUI不相关逻辑,删除无关define,对jsonToStr进行修改
ggssh Apr 29, 2021
4235c98
Merge branch 'ggssh' of https://github.com/Kingtous/WebC-llvm-compile…
ggssh Apr 29, 2021
206e5a8
Merge branch 'sysy' of https://github.com/Kingtous/WebC-llvm-compiler…
ggssh Apr 29, 2021
6ce498c
Merge branch 'ggssh' of https://github.com/Kingtous/WebC-llvm-compile…
ggssh Apr 29, 2021
e06c3e9
opt:删掉CGUI不相关逻辑,删除无关define,对jsonToStr进行修改
ggssh Apr 29, 2021
47eb98f
opt:连接数据库提供端口设置,定义WebCSQLData数据结构对ResultSet以及Statement进行封装,增加判断MySQL连…
ggssh May 2, 2021
a561900
Merge branch 'ggssh' of https://github.com/Kingtous/WebC-llvm-compile…
ggssh May 2, 2021
6ae8a34
opt:连接数据库提供端口设置,定义WebCSQLData数据结构对ResultSet以及Statement进行封装,增加判断MySQL连…
ggssh May 2, 2021
ee41e2f
Merge branch 'sysy' of https://github.com/Kingtous/WebC-llvm-compiler…
ggssh May 2, 2021
0960f38
opt:connect_db增加charset设置字符集类型
ggssh May 2, 2021
043fe9f
opt:connect_db增加charset设置字符集类型
ggssh May 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
commit
  • Loading branch information
nomanker committed Apr 6, 2021
commit 838b741d14b7e3f6d05a18b99f2d3f45a48ee0ca
2 changes: 1 addition & 1 deletion extern/ExternFunctionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ Function *ExternFunctionHandler::getOrAddQueryDB(LLVMContext &context, Module &m
if (func != NIL) {
return func;
}
FunctionType *ty = FunctionType::get(Type::getInt32Ty(context)->getPointerTo(), {Type::getInt8Ty(context)->getPointerTo()},
FunctionType *ty = FunctionType::get(Type::getInt32Ty(context), {Type::getInt8Ty(context)->getPointerTo()},
false);
func = Function::Create(ty, llvm::GlobalValue::ExternalLinkage, "_query_db", module);
return func;
Expand Down
11 changes: 6 additions & 5 deletions module/sql/src/ksql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ int _free_connect() {
}

int _query_db(const char *sqlSentence) {
string temp = sqlSentence;
const char *my = "select * from student";
// string temp = sqlSentence;
string temp = my;
replace(temp.begin(),temp.end(),'\"','\'');
statement = conn->createStatement();
// statement->executeQuery(sqlSentence);
sqlSentence = temp.c_str();
resultSet = statement->executeQuery(sqlSentence);
if (!resultSet) return FAILED;
// _print_json(metaData);
// cout<<_resToJson(resultSet);
cout<<_resToJson(resultSet);
// const char * c = _resToJson(resultSet).c_str();
// SYSY_JSON_DATA temp = strToJson(c);
// cout<<jsonToStr(temp)<<endl;
cout << _resToJson(resultSet) << endl;
return SUCCESS;
// return _resToJson(resultSet);
return 1;
}

string _resToJson(ResultSet *result) {
Expand Down
2 changes: 1 addition & 1 deletion module/sql/src/ksql.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "vector"
#include "hash_set"
//mysql相关参数
#define HOST "127.0.0.1""
#define HOST "127.0.0.1"
#define USER "root"
#define PASSWD "123456"
#define DATABASE "test"
Expand Down
4 changes: 2 additions & 2 deletions module/sql/src/ksqldemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "ksql.h"

int main() {
_connect_db("127.0.0.1","root","123456","school");
_query_db("select subjectno from subject where subjectname like '高等数学%'");
_connect_db("127.0.0.1","root","kcr200123","school");
cout<<_query_db("select * from student");
}
4 changes: 2 additions & 2 deletions module/web/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ add_executable(webdemo src/webdemo.cpp src/web.hpp src/web.cpp)

add_executable(serverdemo src/serverdemo.cpp src/web.hpp src/web.cpp)

target_link_libraries(webdemo Boost::filesystem Boost::system pthread ${SSLLib_LIBRARIES})
target_link_libraries(webdemo Boost::filesystem Boost::system pthread ${SSLLib_LIBRARIES} ksql kjson mysqlcppconn )

target_link_libraries(serverdemo Boost::filesystem Boost::system pthread ${SSLLib_LIBRARIES})
target_link_libraries(serverdemo Boost::filesystem Boost::system pthread ${SSLLib_LIBRARIES} ksql kjson mysqlcppconn )

install(TARGETS web
ARCHIVE DESTINATION ${LOCATION}
Expand Down
9 changes: 6 additions & 3 deletions module/web/src/serverdemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

#include "web.hpp"

const char *say_hello() {
return "hello_world";
string ans="";
const char * say_hello() {
_connect_db("127.0.0.1","root","kcr200123","school");
ans=_query_db("select * from student");
return ans.c_str();
}

const char *say_hi() {
Expand All @@ -15,7 +18,7 @@ const char *say_hi() {

void startServer() {
int id = _web_getServerId("127.0.0.1",9000,2);
_web_addUrlHandler(id, "POST", "/compiler", "text/html", say_hi);
_web_addUrlHandler(id, "GET", "/compiler", "text/html", say_hello);
_web_startServe(id);
}

Expand Down
2 changes: 1 addition & 1 deletion module/web/src/web.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <map>
#include <set>

#include "./module/sql/src/ksql.h"
#include <boost/beast.hpp>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
Expand Down
52 changes: 29 additions & 23 deletions test/test.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
//str hi() {
// str a = '<h1>hello from kingtous compiler</h1>';
// ret a;
//}
str hi() {
connect_db('127.0.0.1','root','kcr200123','school');
int b=query_db('select * from student');
str a = '<h1>hello from kingtous compiler</h1>';
ret a;
}

//int main() {
// echo('init...');
//} echo(hi());
// str host = '127.0.0.1';
// int port = 9000;
// int core = 2;
// echo('get server...');
// int server_id = getServer(host, port, core);
// echo('server id is', server_id);
int main() {
echo('init...');
echo(hi());
str host = '127.0.0.1';
int port = 9000;
int core = 2;
echo('get server...');
int server_id = getServer(host, port, core);
echo('server id is', server_id);
addUrlHandler(server_id, 'GET', '/compiler', 'text/html', hi);
echo('start server in host', host, ',port is', port);
startServer(server_id);
ret
0;
}
//int main(){
// int server_id=getServer('127.0.0.1', 9000, 2);
// addUrlHandler(server_id, 'GET', '/compiler', 'text/html', hi);
// echo('start server in host', host, ',port is', port);
// startServer(server_id);
// ret
// 0;
//}
int main(){
connect_db('127.0.0.1','root','123456','school');
query_db('select subjectno from subject where subjectname like "高等数学%"');
ret 0;
}
// connect_db('127.0.0.1','root','kcr200123",'school');
// query_db('select * from student');
//// int a =12;
//// echo(a);
// ret 0;
//}