Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Regarding storing structures in database

Regarding storing structures in database

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelp
11 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U User 7860594

    I need to store a structure in a database..but the structure contains another structure..can anybody help me plz

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    Are you trying to store all this data in one database field or store its contents in separate fields? Please provide more details.

    Use the best guess

    1 Reply Last reply
    0
    • U User 7860594

      I need to store a structure in a database..but the structure contains another structure..can anybody help me plz

      M Offline
      M Offline
      Marco Bertschi
      wrote on last edited by
      #3

      Given that you have two structures, you need something like a foreign key to resolve them when loading them from database. Given there is structure #1:

      struct numberOne{
      int childStructId,
      int someValue
      };

      and struct #2:

      struct numberTwo{
      int id,//needs to be unique
      int anotherValue
      };

      You need now a database which has two tables, one to store struct #1 and another one for struct #2: The table for struct #1 has two fields, for the childStructId and onther one for someValue. The table for struct #2 has also two fields, one for its unique Id and another one for anotherValue. Afterwards you can load struct #1 from database, and according to the childStructId you can load struct #2 from the database. I was just guessing what you want, please come back to me if you have further questions.

      cheers Marco Bertschi


      Twitter | Articles


      You have absolutely no idea how glad I am that I have no idea at all. - OriginalGriff I'm at peace with the world and myself. - Me

      U 1 Reply Last reply
      0
      • M Marco Bertschi

        Given that you have two structures, you need something like a foreign key to resolve them when loading them from database. Given there is structure #1:

        struct numberOne{
        int childStructId,
        int someValue
        };

        and struct #2:

        struct numberTwo{
        int id,//needs to be unique
        int anotherValue
        };

        You need now a database which has two tables, one to store struct #1 and another one for struct #2: The table for struct #1 has two fields, for the childStructId and onther one for someValue. The table for struct #2 has also two fields, one for its unique Id and another one for anotherValue. Afterwards you can load struct #1 from database, and according to the childStructId you can load struct #2 from the database. I was just guessing what you want, please come back to me if you have further questions.

        cheers Marco Bertschi


        Twitter | Articles


        You have absolutely no idea how glad I am that I have no idea at all. - OriginalGriff I'm at peace with the world and myself. - Me

        U Offline
        U Offline
        User 7860594
        wrote on last edited by
        #4

        sir, first of all thank u so much for ur reply.. what i need is for example there is a structure struct example { int id; string name; struct example2 { int value; } }; now i need to store this structure in a database...as i'm new to database i dnt have any idea of it...so plz help me...also i'm using sqlite3 database

        M J 2 Replies Last reply
        0
        • U User 7860594

          sir, first of all thank u so much for ur reply.. what i need is for example there is a structure struct example { int id; string name; struct example2 { int value; } }; now i need to store this structure in a database...as i'm new to database i dnt have any idea of it...so plz help me...also i'm using sqlite3 database

          M Offline
          M Offline
          Marco Bertschi
          wrote on last edited by
          #5

          Member 7894601 wrote:

          first of all thank u so much for ur reply..

          You're welcome.

          Member 7894601 wrote:

          now i need to store this structure in a database...as i'm new to database i
          dnt have any idea of it...so plz help me...also i'm using sqlite3 database

          You can find an intro of how to connect to a SQLite database at the SQLite website[^]. The people of the Database forum[^] will help you to find out which tables you will need to create a reliable database.

          cheers Marco Bertschi


          Twitter | Articles


          You have absolutely no idea how glad I am that I have no idea at all. - OriginalGriff I'm at peace with the world and myself. - Me

          1 Reply Last reply
          0
          • U User 7860594

            sir, first of all thank u so much for ur reply.. what i need is for example there is a structure struct example { int id; string name; struct example2 { int value; } }; now i need to store this structure in a database...as i'm new to database i dnt have any idea of it...so plz help me...also i'm using sqlite3 database

            J Offline
            J Offline
            Jochen Arndt
            wrote on last edited by
            #6

            You may create two tables where one contains a reference (foreign key) to the other:

            TABLE example2
            INT id unique ID, usually auto increment
            INT value

            TABLE example
            INT id
            VARCHAR name
            INT id2 foreign key to access table example2

            U 1 Reply Last reply
            0
            • J Jochen Arndt

              You may create two tables where one contains a reference (foreign key) to the other:

              TABLE example2
              INT id unique ID, usually auto increment
              INT value

              TABLE example
              INT id
              VARCHAR name
              INT id2 foreign key to access table example2

              U Offline
              U Offline
              User 7860594
              wrote on last edited by
              #7

              but initially how to create a database with two tables using sqlite3

              J 1 Reply Last reply
              0
              • U User 7860594

                but initially how to create a database with two tables using sqlite3

                J Offline
                J Offline
                Jochen Arndt
                wrote on last edited by
                #8

                Searching the web for 'sqlite tutorial' should help. http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html[^] is one result which shows you how to create a database and add tables to it.

                1 Reply Last reply
                0
                • U User 7860594

                  I need to store a structure in a database..but the structure contains another structure..can anybody help me plz

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #9

                  Member 7894601 wrote:

                  can anybody help me plz

                  The first step is that you need to learn - How to create a database - How to create tables - How to store and retrieve data from a table None of that has anything to do with your structures, so don't try to do that until you understand the above.

                  U 2 Replies Last reply
                  0
                  • J jschell

                    Member 7894601 wrote:

                    can anybody help me plz

                    The first step is that you need to learn - How to create a database - How to create tables - How to store and retrieve data from a table None of that has anything to do with your structures, so don't try to do that until you understand the above.

                    U Offline
                    U Offline
                    User 7860594
                    wrote on last edited by
                    #10

                    Sir, i am nw able to create a database...nw my requirement is how to store the details of files and folders in the database..

                    1 Reply Last reply
                    0
                    • J jschell

                      Member 7894601 wrote:

                      can anybody help me plz

                      The first step is that you need to learn - How to create a database - How to create tables - How to store and retrieve data from a table None of that has anything to do with your structures, so don't try to do that until you understand the above.

                      U Offline
                      U Offline
                      User 7860594
                      wrote on last edited by
                      #11

                      sir, nw i am able to create a sqlite3 database...but nw i face a problem of storing a variable which is wchar_t...which datatype should i use...plz help me

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups