Skip to content

Commit

Permalink
修改SQLite3获取数据逻辑,ORM,Logger热更新bug
Browse files Browse the repository at this point in the history
Signed-off-by: sylar-yin <564628276@qq.com>
  • Loading branch information
sylar-yin committed Jul 14, 2019
1 parent bfc681a commit e2b3014
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include (cmake/utils.cmake)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -fPIC -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -Wno-deprecated-declarations")

include_directories(.)
include_directories(/apps/sylar/include)
Expand Down Expand Up @@ -188,8 +188,7 @@ sylar_add_executable(bin_sylar "sylar/main.cc" sylar "${LIBS}")
set_target_properties(bin_sylar PROPERTIES OUTPUT_NAME "sylar")

#add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/orm_out)
#set(OLIBS ${LIBS})
#set(OLIBS ${OLIBS} orm_data)
#set(OLIBS ${LIBS} orm_data)
#sylar_add_executable(test_orm "tests/test_orm.cc" orm_data "${OLIBS}")

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
Expand Down
3 changes: 3 additions & 0 deletions bin/conf/system.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
server:
work_path: /apps/work/sylar
pid_file: sylar.pid
5 changes: 1 addition & 4 deletions sylar/db/sqlite3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,7 @@ SQLite3Stmt::~SQLite3Stmt() {
}

SQLite3Data::ptr SQLite3Stmt::query() {
if(step() == SQLITE_ROW) {
return SQLite3Data::ptr(new SQLite3Data(shared_from_this()));
}
return nullptr;
return SQLite3Data::ptr(new SQLite3Data(shared_from_this()));
}

int SQLite3Stmt::execute() {
Expand Down
2 changes: 2 additions & 0 deletions sylar/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,8 @@ struct LogIniter {
if(!(i == *it)) {
//修改的logger
logger = SYLAR_LOG_NAME(i.name);
} else {
continue;
}
}
logger->setLevel(i.level);
Expand Down
14 changes: 10 additions & 4 deletions sylar/orm/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ void Table::gen_dao_src(std::ofstream& ofs) {
ofs << " if(!rt) {" << std::endl;
ofs << " return 0;" << std::endl;
ofs << " }" << std::endl;
ofs << " do {" << std::endl;
ofs << " while (rt->next()) {" << std::endl;
ofs << " " << GetAsClassName(class_name) << "::ptr v(new "
<< GetAsClassName(class_name) << ");" << std::endl;

Expand Down Expand Up @@ -709,7 +709,7 @@ void Table::gen_dao_src(std::ofstream& ofs) {

PARSE_OBJECT(" ");
ofs << " results.push_back(v);" << std::endl;
ofs << " } while (rt->next());" << std::endl;
ofs << " };" << std::endl;
ofs << " return 0;" << std::endl;
ofs << "}" << std::endl << std::endl;

Expand Down Expand Up @@ -748,6 +748,9 @@ void Table::gen_dao_src(std::ofstream& ofs) {
ofs << " if(!rt) {" << std::endl;
ofs << " return nullptr;" << std::endl;
ofs << " }" << std::endl;
ofs << " if(!rt->next()) {" << std::endl;
ofs << " return nullptr;" << std::endl;
ofs << " }" << std::endl;
ofs << " " << GetAsClassName(class_name) << "::ptr v(new "
<< GetAsClassName(class_name) << ");" << std::endl;
PARSE_OBJECT(" ");
Expand Down Expand Up @@ -797,6 +800,9 @@ void Table::gen_dao_src(std::ofstream& ofs) {
ofs << " if(!rt) {" << std::endl;
ofs << " return nullptr;" << std::endl;
ofs << " }" << std::endl;
ofs << " if(!rt->next()) {" << std::endl;
ofs << " return nullptr;" << std::endl;
ofs << " }" << std::endl;
ofs << " " << GetAsClassName(class_name) << "::ptr v(new "
<< GetAsClassName(class_name) << ");" << std::endl;
PARSE_OBJECT(" ");
Expand Down Expand Up @@ -844,12 +850,12 @@ void Table::gen_dao_src(std::ofstream& ofs) {
ofs << " if(!rt) {" << std::endl;
ofs << " return 0;" << std::endl;
ofs << " }" << std::endl;
ofs << " do {" << std::endl;
ofs << " while (rt->next()) {" << std::endl;
ofs << " " << GetAsClassName(class_name) << "::ptr v(new "
<< GetAsClassName(class_name) << ");" << std::endl;
PARSE_OBJECT(" ");
ofs << " results.push_back(v);" << std::endl;
ofs << " } while (rt->next());" << std::endl;
ofs << " };" << std::endl;
ofs << " return 0;" << std::endl;
ofs << "}" << std::endl << std::endl;
}
Expand Down
3 changes: 3 additions & 0 deletions template/bin/conf/system.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
server:
work_path: /apps/work/sylar
pid_file: sylar.pid
8 changes: 4 additions & 4 deletions tests/test_sqlite3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,22 @@ XX(create table user (
return 0;
}

do {
while(ds->next()) {
//SYLAR_LOG_INFO(g_logger) << "query ";
} while(ds->next());
};

//const char v[] = "hello ' world";
const std::string v = "hello ' world";
db->execStmt("insert into user(name) values (?)", v);

auto dd = std::dynamic_pointer_cast<sylar::SQLite3Data>(db->queryStmt("select * from user"));
do {
while(dd->next()) {
SYLAR_LOG_INFO(g_logger) << "ds.data_count=" << dd->getDataCount()
<< " ds.column_count=" << dd->getColumnCount()
<< " 0=" << dd->getInt(0) << " 1=" << dd->getText(1)
<< " 2=" << dd->getText(2)
<< " 3=" << dd->getText(3);
} while(dd->next());
}

test_batch(db);
return 0;
Expand Down

0 comments on commit e2b3014

Please sign in to comment.