We have been working to solve the issue early in the morning. This is a sample code to clearly show the situation. There are also more than 100 tables are waiting to get their records to calculate the results . Any idea ?

conn.h

#include "stdafx.h"
static double global ; 
using namespace System;
using namespace System::Data::SQLite;

class conn 
{
    public:
    static double energy_liver_calf; // global alternative here
        //conn(){energy_liver_calf = 10 ;}
    //~conn(){};

    static double liver_calf_nutrition_facts()  
    {
    // (+)
       command->CommandText = "select energy_kcal from  meatProducts where food_name    = 'liver_calf' "; // sample query
              SQLiteDataReader ^dataReader = command->ExecuteReader();

             System::String^ kcal ;


             if (dataReader->HasRows)
             {
                    while (dataReader->Read())
                    {   
                    kcal = dataReader["energy_kcal"]->ToString();

                     }
             }

       energy_liver_calf = System::Convert::ToDouble(kcal);         
             global = energy_liver_calf ;
             return global ;  // returns 135  ( RIGHT ! )
    }

    static double get_energy_liver_calf()  
    {
    return global;  // returns 0 ( WRONG !!!!!!!!!!!!!!!!!!!!!!!!!!!! )
    }


};

Recommended Answers

All 3 Replies

Since this is managed c++ you must be using VC++. Use your compiler's debugger to find out when the value of the global changes. Either get_energy_liver_calf() is gbetting called before the value of global is set, or something else is changing it.

You might also surround global with a namespace of your choice to make sure there is no possibility of name clashes.

You are right about using managed VC++ . I listened the suggestion, unfortunately it doesn't make sense . Still insisting on it is a visual studio bug

#include "stdafx.h"
using namespace System::Data::SQLite;

namespace first 
{
double global = 1 ;
}

class conn {
public:
    static double get_LiverCalf_NutritionFacts()
    {
             // ( + )

             System::String^ kcal ;


       if (dataReader->HasRows)
       {
        while (dataReader->Read())
        {   
        kcal = dataReader["energy_kcal"]->ToString();

          }
       }

             using namespace first;    
             global = System::Convert::ToDouble(kcal); 
             return global ;   //  returns 135  ( RIGHT ! )
    }

    static double get_Liver_Calf_Energy()
    {
    using namespace first; 
    return global ;   // returns 1   ( still WRONG !!!!!!)
    }

};

OK , the problem solved . Thanks for relevance .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.