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

  • SEARCH
  • Home
  • 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 7751035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:26:44+00:00 2026-06-01T11:26:44+00:00

I’m writing a very simple and small wrapper around sqlite3, and use sqlite3_get_table() to

  • 0

I’m writing a very simple and small wrapper around sqlite3, and use sqlite3_get_table() to fetch the results as char**. I use a base data class to be able to store the fields in a uniform container, namely record here, and then fetch each data type specifically using derived types.

This is my base class:

class data
{
    private:
        uint sz;
        virtual void abstract() = 0;

    public:
        inline data(char* pd);
        inline data();
        uint size() {return sz;}
};

and here’s the sample derived class:

class str : public data
{
    private:
        string* pdata;
        virtual void abstract() {}

    public:
        inline str(char* pd);
        inline operator string();
        inline operator const char*();
};

and the record class:

class record
{
    private:
        ushort cols;
        data** entries;
    public:
        record(char** ppdata, uint col_count);
        inline data* operator [](ushort field);
        inline uint num_fields() {return cols;}
};

record‘s operator[] (inline data* operator [](ushort field);) allows me to access the base data class this way:

db::str* mys = dynamic_cast<db::str*>((*record)[3]);

and compile: g++ -o main -lsqlite3 main.cpp under Arch Linux, and there’s no problem in compilation. But when I run it I get Segmentation Fault.

Commenting out the dynamic_cast line makes me happy, but I personally guess I’m doing the downcast wrong in someway, rather than thinking there’s a problem with definition or use of the data class.

I also appreciate any radical offenses to my code, since I know I’m a newbie. Thanks so much.

  • 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-01T11:26:45+00:00Added an answer on June 1, 2026 at 11:26 am

    Thank both of you TC1 and Mark Ransom. I tried twiddling my problem and I finally came to realize that this is the best solution, comparing it’s advantages to it’s trade offs, for a simple wrapper like the one I’m writing (sqlite3’s sqlite3_get_table()):

    enum types {INT, FLOAT, STRING, BLOB, NUL};
    
    class bad_type {};
    
    class data
    {
        private:
            void* pdata;
            types type;
    
        public:
            data(int dt)
            {
                int* tmp = new int(dt);
                pdata = static_cast<void*>(tmp);
                type = INT;
            }
            // constructors for other types to be added in a similar fashion.
    
            operator int()
            {
                if (type == INT)
                    return *(static_cast<int*>(pdata));
                throw bad_type();
            }
            // operators for other types to be added in a similar fashion.
    };
    

    This way I’m making the data* a very suitable pointer type for making a heterogeneous container (Sorry that I didn’t know the word when I asked the question 😉 ) in such a case that data types are limited, 5 in this case, since its working at a somehow low level.

    I just used it in my test main like this:

    data* array[3];
    array[0] = new data(3);
    
    cout << *(array[0]);
    

    And it does give me 3, and certainly its gotta be possible to apply it to any other type too, especially at low level in this case that types are often fundamental rather than say sophisticated inherited ones.

    I’ve come to believe that in such cases static_cast can be tolerated, please correct me if I’m wrong. And also I’m really willing to know of both of your criticisms and appreciations about this solution, since it helps me learn more as a beginner.

    Thank you.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.