Commit e1dd2134 authored by Casualet's avatar Casualet

add count.sh

parent 32bba12d
......@@ -297,7 +297,7 @@ void myNext(std::string client,bool isFirst,ResType inRes) {
switch (result_type){
//execute the query, fetch the results, and call next again
case AbstractQueryExecutor::ResultType::QUERY_COME_AGAIN: {
//std::cout<<RED_BEGIN<<"case one"<<COLOR_END<<std::endl;
std::cout<<RED_BEGIN<<"case one"<<COLOR_END<<std::endl;
const auto &output =
std::get<1>(new_results)->extract<std::pair<bool, std::string> >();
const auto &next_query = output.second;
......@@ -311,7 +311,7 @@ void myNext(std::string client,bool isFirst,ResType inRes) {
//only execute the query, without processing the retults
case AbstractQueryExecutor::ResultType::QUERY_USE_RESULTS:{
//std::cout<<RED_BEGIN<<"case two"<<COLOR_END<<std::endl;
std::cout<<RED_BEGIN<<"case two"<<COLOR_END<<std::endl;
const auto &new_query =
std::get<1>(new_results)->extract<std::string>();
auto resRemote = executeAndGetResultRemote(globalConn,new_query);
......@@ -321,7 +321,7 @@ void myNext(std::string client,bool isFirst,ResType inRes) {
//return the results to the client directly
case AbstractQueryExecutor::ResultType::RESULTS:{
//std::cout<<RED_BEGIN<<"case three"<<COLOR_END<<std::endl;
std::cout<<RED_BEGIN<<"case three"<<COLOR_END<<std::endl;
const auto &res = new_results.second->extract<ResType>();
parseResType(res);
break;
......
......@@ -7,7 +7,7 @@
using namespace std;
extern Connect *con;
string createSelect(string database,string table,bool isQuote=true){
string createSelect(string database,string table,int quote){
auto dbresult = con->execute(string("SELECT * FROM `")+database+"`.`"+string(table)+"` LIMIT 1;");
DBResult * result = dbresult.get();
vector<vector<string>> rows = result->getRows();
......@@ -17,11 +17,11 @@ string createSelect(string database,string table,bool isQuote=true){
for(int i=0;i<types.size();i++){
if(IS_NUM(types[i])){
head += fields[i]+",";
}
else{
if(isQuote)
}else{
if(quote==1)
head+=string("QUOTE(")+fields[i]+") AS quo"+fields[i]+" ,";
else head+=string("HEX(")+fields[i]+") AS hex"+fields[i]+" ,";
else if(quote==2) head+=string("HEX(")+fields[i]+") AS hex"+fields[i]+" ,";
else if(quote==3) head += fields[i]+",";
}
}
head[head.size()-1]=' ';
......@@ -72,16 +72,17 @@ vector<string> getTables(string db){
int main(int argc,char**argv){
system("rm -rf allTables");
system("mkdir allTables");
if(argc!=2){
cout<<"db"<<endl;
if(argc!=3){
cout<<"db, 1quote/2hex/3plain"<<endl;
return 0;
}
string option(argv[2]);
string num = string(argv[1]);
vector<string> tablesprefix = getTables(string(argv[1]));
for(auto item:tablesprefix){
string query = createSelect(string(argv[1]),item);
string query = createSelect(string(argv[1]),item,stoi(option));
backupselect(query,string("allTables/")+item+"/");
}
return 0;
......
## specify the database name, and get the total count of all the tables in that database
function mysql_command(){
cmd=\'$1\'
#single quoted ${cmd} is not recognised
final="mysql -uroot -pletmein -h127.0.0.1 -e ${cmd}"
#eval can not be ommited here, can not just use $final only for this command
res=`eval $final`
echo $res
}
function show_table_counts(){
db=$1
raw=`mysql -uroot -pletmein -h127.0.0.1 -e "use $db;show tables;"| awk '{print $1}'`
arr=($raw)
len=${#arr[@]}
for((i=1;i<$len;i++))
do
res=`mysql_command "SELECT COUNT(*) AS total_count FROM $1.${arr[$i]}"`
echo ${arr[$i]},$res
done
}
show_table_counts $1
#res=`mysql_command 'show databases'`
#echo $res
##only support numeric return value
#echo $?
......@@ -108,8 +108,7 @@ IntFromBytes(const unsigned char * bytes, unsigned int noBytes)
}
uint64_t
uint64FromZZ(ZZ val)
{
uint64FromZZ(ZZ val){
uint64_t res = 0;
uint64_t mul = 1;
while (val > 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment