Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8596705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:44:35+00:00 2026-06-12T00:44:35+00:00

I need help in developing a faster algorithm to be used in my CGI

  • 0

I need help in developing a faster algorithm to be used in my CGI file (using C). I have four sqlite3 database tables that contains two parameters attack_type and defend_type. These tables are mod_no, mod_ne, mod_av, and mod_se. When the function double modifier(int attack_type, int defend), an sqlite3 statement selects from the database if an entry of attack_type and defend_type exists together in one of the tables. Depending on which table the sqlite3 statement yields == 1, the function will return a specific value of data type double.

Here is the code:

double modifier(int attack_type, int defend_type)
{
    sqlite3 *conn;
    sqlite3_stmt *res;
    sqlite3_open("MP1.sl3", &conn);
    int i,n;
    int eff;
    char    temp[MAXLENGTH];
    char    mod_tables[4][8] = {"mod_no","mod_ne","mod_av","mod_se"};
    for (i = 0; i <=3; i++) {
        printf(temp, "select exists(select atk_typ,pok_typ from %s where atk_typ = %d and pok_typ = %d);",mod_tables[i],atk_typ, pok_typ);
        sqlite3_prepare_v2(conn,temp,MAXLENGTH,&res,NULL);
        while(sqlite3_step(res) != SQLITE_ROW) {
            n = sqlite3_column_int(res,0);
        }
        sqlite3_finalize(res);
        if (n == 1) eff = i;
        if (eff == i) break;

    }
    sqlite3_close(conn);
    return eff/(double)2;   
}

The problem with this code is (1) It does not return any value, and (2) It is slow. To test if the problem is with the code, I initialized eff = 2 so that the function returns 1. The CGI file ran fast. But when I removed the initial value, it returned to being slow.

I need to have a working function. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:44:36+00:00Added an answer on June 12, 2026 at 12:44 am

    Here is one possible optimisation:

    select exists(select atk_typ,pok_typ from mod_no where atk_typ = %d and pok_typ = %d);",mod_tables[i],atk_typ, pok_typ)
    union
    select exists(select atk_typ,pok_typ from mod_ne where atk_typ = %d and pok_typ = %d);",mod_tables[i],atk_typ, pok_typ)
    union
    select exists(select atk_typ,pok_typ from mod_av where atk_typ = %d and pok_typ = %d);",mod_tables[i],atk_typ, pok_typ)
    union
    select exists(select atk_typ,pok_typ from mod_se where atk_typ = %d and pok_typ = %d);",mod_tables[i],atk_typ, pok_typ)
    

    Then you only have 1 query and can get rid of the outer for loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this JUnit test that I need help developing a Interface and Class
Need help with a query that I wrote: I have three tables Company id
i'm new at IPhone SDK Developing and now i need some help. I have
I am developing a WPF app using MVVM and need some help. for the
I have this idea which I need some help with. Currently I am developing
I need help developing a circle detection algorithm to detect snooker balls. Does anyone
I am developing a location based application.I need help for that application My requirement
Other time I need your help, I am developing an app in C# using
I need some help developing my new custom built input method. I'm using InputConnection.sendKeyEvent
i am developing an online mapping application using OpenLayers + OpenStreetMaps. i need help

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.