Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

XBasic Restructuring Table

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    XBasic Restructuring Table

    I have a table with 200 records which I imported from a comma delimited text file that I want to restructure. I have tried the code below, but it throws away the records. Is there a way that the table structure can be altered using XBasic, without throwing away the data? or is there another approach to this

    dim tblCh as P
    tblch = table.open("1wthdrxp",FILE_RW_EXCLUSIVE)
    tblch.table_restructure(<<%str%
    CUSTOMER_ID,Character,8,0
    FIRSTNAME,Character,25,0
    LASTNAME,Character,25,0
    COMPANY,Character,32,0
    PN=PHONE,Character,20,0
    FAX,Character,20,0
    DOB,Date,8,0
    %str%)
    tblch.close()

    Manay Thanks,

    Peter

    #2
    Originally posted by gagsoft
    I have a table with 200 records which I imported from a comma delimited text file that I want to restructure. I have tried the code below, but it throws away the records. Is there a way that the table structure can be altered using XBasic, without throwing away the data? or is there another approach to this

    dim tblCh as P
    tblch = table.open("1wthdrxp",FILE_RW_EXCLUSIVE)
    tblch.table_restructure(<<%str%
    CUSTOMER_ID,Character,8,0
    FIRSTNAME,Character,25,0
    LASTNAME,Character,25,0
    COMPANY,Character,32,0
    PN=PHONE,Character,20,0
    FAX,Character,20,0
    DOB,Date,8,0
    %str%)
    tblch.close()

    Manay Thanks,

    Peter
    My first question would be why would you need to do this with xbasic when you could simply open the table in the control panel and restructure to suit?

    A second thought would be to import to a temporary table and then append the records to a created table with the desired sturcture.
    There can be only one.

    Comment


      #3
      Peter,

      the help file explanation for the table_restructure() method mentions several different ways data loss can occur. I suspect one of two things. One of the methods mentioned in the documentation occurred, or your table name is causing you grief.

      From the help files:

      Table and Field Names

      Alpha Five recommends that table names, field names, and paths to your files start with a letter (A-Z or a-z) and be composed of letters, numbers (0-9), and underscore (_) characters. Do not use tilde "~" characters.
      Your table name begins with a digit, which is NOT recommended.

      What was your original table structure?

      --tom

      Comment


        #4
        Originally posted by Stan Mathews
        My first question would be why would you need to do this with xbasic when you could simply open the table in the control panel and restructure to suit?

        A second thought would be to import to a temporary table and then append the records to a created table with the desired sturcture.
        Hi Stan

        The append operation does not work because there are 2 date fields in the final table. The table that gets imported is a comma delimited text file which will be imported by the user. I want the user to be able to do the imorting and appending in one go.

        Thanks,

        Peter

        Comment


          #5
          Originally posted by Tom Cone Jr
          Peter,

          the help file explanation for the table_restructure() method mentions several different ways data loss can occur. I suspect one of two things. One of the methods mentioned in the documentation occurred, or your table name is causing you grief.

          From the help files:



          Your table name begins with a digit, which is NOT recommended.

          What was your original table structure?

          --tom
          Thanks Tom

          I will try renaming the table name.

          Many thanks,
          Peter

          Comment


            #6
            Originally posted by gagsoft
            Hi Stan

            The append operation does not work because there are 2 date fields in the final table. The table that gets imported is a comma delimited text file which will be imported by the user. I want the user to be able to do the imorting and appending in one go.

            Thanks,

            Peter
            You can append an expression which would convert the value in the temporary table from character to date. I import and append such files on a regular basis. Usually the files I import are recognized as all character values. I use expressions to make some fields in the final table numeric and some become dates. You can even append a value to the final table that doesn't even exist in the transaction (temporary table) by specifying a hard coded value, like the current date, or the value of some variable that is set before the append occurs.

            This can all be done with saved operations or the modified xbasic of the same. One button used by the user can trigger both.
            There can be only one.

            Comment


              #7
              XBasic Restructuring Table

              Hi Tom

              I did the following:
              Renamed the table to test.
              Renamed all field with no underscores
              Renamed the fields in the script removing the underscores see below:
              dim tblRes as P
              tblRes = table.open("Test",FILE_RW_EXCLUSIVE)
              tblRes.table_restructure(<<%str%
              CUSTOMERID,Character,8,0
              FIRSTNAME,Character,25,0
              LASTNAME,Character,25,0
              COMPANY,Character,32,0
              PHONE,Character,20,0
              FAX,Character,20,0
              ADDRESS1,Character,40,0
              ADDRESS2,Character,40,0
              BCITY,Character,20,0
              DStart,Date,8,0
              BPOSTALCODE,Character,10,0
              BCOUNTRY,Character,20,0
              SADDRESS1,Character,40,0
              DateReq,Date,8,0
              SCITY,Character,20,0
              SSTATEREGION,Character,20,0
              SPOSTALCODE,Character,10,0
              SCOUNTRY,Character,20,0
              SSAME,Logical,1,0
              EMAIL,Character,60,0
              %str%)
              tblRes.close()

              Maybe I should also mention that the fields in the table being restructured are named as follows: Field1, Field2, Field3..........

              It Still throws away the data.
              Any ideas?

              Many Thanks,

              Peter

              Comment


                #8
                Hi Stan

                Please accept my apolgies. I only saw your reply now. Would it be possible to show me an extract of the code to put me on the right track?

                Many Thanks,

                Peter.

                Comment


                  #9
                  Peter,

                  Let me ask again.

                  What is the original table structure?

                  You've supplied fieldnames (Field1, Field2, etc.) but not data types or widths.

                  -- tom

                  Comment


                    #10
                    XBasic Restructuring Table

                    Hi Tom

                    Humble apologies for that oversight.
                    The table Structure for the imported table

                    1 FIELD1 C 6 0
                    2 FIELD2 N 7 0
                    3 FIELD3 C 25 0
                    4 FIELD4 C 7 0
                    5 FIELD5 N 8 2
                    6 FIELD6 N 11 6
                    7 FIELD7 C 3 0
                    8 FIELD8 N 6 0
                    9 FIELD9 C 25 0
                    10 FIELD10 C 8 0
                    11 FIELD11 C 6 0
                    12 FIELD12 C 1 0
                    13 FIELD13 C 3 0
                    14 FIELD14 C 8 0
                    15 FIELD15 C 5 0
                    16 FIELD16 C 1 0
                    17 FIELD17 C 1 0
                    18 FIELD18 C 1 0
                    19 FIELD19 C 4 0
                    20 FIELD20 N 7 0
                    21 FIELD21 C 6 0
                    22 FIELD22 C 1 0
                    23 FIELD23 C 2 0

                    Thanks,
                    Peter

                    Comment


                      #11
                      Ok. I think the data loss is happening because of mismatches in the table structures. The sequence in your original table does not match the sequence in your final structure. Alpha Five has to move particular field values to new slots in each record's structure. This is failing. Stan's suggestion to use a temporary table and then do an append, where the append matches source and target fields explicitly, sounds like a practical solution. If time permits I'll do a bit of experimenting with an xbasic solution.

                      ----------------------------------------------------------------------------
                      Update
                      ----------------------------------------------------------------------------
                      Peter, you'll need to read the help file closely for the options available with <tbl>.table_restructure(). It's quite powerful and flexible.

                      Turns out your syntax is wrong, mainly by failing to explicitly tie new fieldnames to old fieldnames.

                      The attached example database contains two scripts in the Code page of the control panel. The first script (Chg_Fld_Seq) simply reorganizes the existing fields putting them in a different order within each record. The second script (Put flds to orig seq) puts them back in the original order.

                      This same approach can be used to change the field width and field name of any field in the table.

                      I haven't experimented with changing data types using this table method. Just rearranging field order within each record, changing field names, and changing field widths. These three work as advertised, but you MUST follow the specific sequence detailed in the help file.

                      --------------------------------------------------------------
                      Update 2
                      --------------------------------------------------------------

                      Turns out the table_restructure() method can handle data type conversions just fine, within the same limits applicable to manual restructuring of table (as explained the help docs).

                      Using the attached Example database, here is another script which does several interesting things in one step:

                      a) re-sequences the field order within each record
                      b) changes the data type for the Id_num field from c,5,0 to n,5,0
                      c) changes the field name for the Age field to C_Age
                      d) changes the data type for the Age field (now C_Age) from n,3,0 to c,3,0

                      Pretty impressive!

                      Code:
                      'Date Created: 26-Dec-2005 03:41:12 PM
                      'Last Updated: 26-Dec-2005 03:41:12 PM
                      'Created By  : TEC
                      'Updated By  : TEC
                      tbl = table.open("People")
                      
                      'Rearrange the order of fields within table structure
                      'Original field order and structure is
                      'Id_num,c,5,0
                      'Age,n,3,0
                      'Bdate,d,8,0
                      'Fname,c,20,0
                      'Lname,c,20,0
                      
                      'AND then change Id_num to N, 5, 0
                      
                      'AND then change name of Age field to c_Age
                      
                      'AND then change data type for C_Age field to C, 3
                      
                      list = <<%str%
                      Lname = Lname,c,20,0
                      Fname = Fname,c,20,0
                      c_Age = Age,c,3,0
                      Bdate = Bdate,d,8,0
                      Id_Num = Id_num,n,5,0
                      %str%
                      tbl.table_restructure(list)
                      -- tom
                      Last edited by Tom Cone Jr; 12-26-2005, 04:46 PM.

                      Comment


                        #12
                        Originally posted by gagsoft
                        Hi Stan

                        Please accept my apolgies. I only saw your reply now. Would it be possible to show me an extract of the code to put me on the right track?

                        Many Thanks,

                        Peter.
                        Attachment is an example.
                        Last edited by Stan Mathews; 03-28-2006, 03:24 PM.
                        There can be only one.

                        Comment


                          #13
                          Originally posted by Tom Cone Jr
                          Ok. I think the data loss is happening because of mismatches in the table structures. The sequence in your original table does not match the sequence in your final structure. Alpha Five has to move particular field values to new slots in each record's structure. This is failing. Stan's suggestion to use a temporary table and then do an append, where the append matches source and target fields explicitly, sounds like a practical solution. If time permits I'll do a bit of experimenting with an xbasic solution.

                          ----------------------------------------------------------------------------
                          Update
                          ----------------------------------------------------------------------------
                          Peter, you'll need to read the help file closely for the options available with <tbl>.table_restructure(). It's quite powerful and flexible.

                          Turns out your syntax is wrong, mainly by failing to explicitly tie new fieldnames to old fieldnames.

                          The attached example database contains two scripts in the Code page of the control panel. The first script (Chg_Fld_Seq) simply reorganizes the existing fields putting them in a different order within each record. The second script (Put flds to orig seq) puts them back in the original order.

                          This same approach can be used to change the field width and field name of any field in the table.

                          I haven't experimented with changing data types using this table method. Just rearranging field order within each record, changing field names, and changing field widths. These three work as advertised, but you MUST follow the specific sequence detailed in the help file.

                          --------------------------------------------------------------
                          Update 2
                          --------------------------------------------------------------

                          Turns out the table_restructure() method can handle data type conversions just fine, within the same limits applicable to manual restructuring of table (as explained the help docs).

                          Using the attached Example database, here is another script which does several interesting things in one step:

                          a) re-sequences the field order within each record
                          b) changes the data type for the Id_num field from c,5,0 to n,5,0
                          c) changes the field name for the Age field to C_Age
                          d) changes the data type for the Age field (now C_Age) from n,3,0 to c,3,0

                          Pretty impressive!

                          Code:
                          'Date Created: 26-Dec-2005 03:41:12 PM
                          'Last Updated: 26-Dec-2005 03:41:12 PM
                          'Created By  : TEC
                          'Updated By  : TEC
                          tbl = table.open("People")
                          
                          'Rearrange the order of fields within table structure
                          'Original field order and structure is
                          'Id_num,c,5,0
                          'Age,n,3,0
                          'Bdate,d,8,0
                          'Fname,c,20,0
                          'Lname,c,20,0
                          
                          'AND then change Id_num to N, 5, 0
                          
                          'AND then change name of Age field to c_Age
                          
                          'AND then change data type for C_Age field to C, 3
                          
                          list = <<%str%
                          Lname = Lname,c,20,0
                          Fname = Fname,c,20,0
                          c_Age = Age,c,3,0
                          Bdate = Bdate,d,8,0
                          Id_Num = Id_num,n,5,0
                          %str%
                          tbl.table_restructure(list)
                          -- tom
                          Hi Tom

                          Thanks for all the help, I got sorted.
                          Enjoy what is left of the festive season.

                          Many thanks,

                          Peter

                          Comment


                            #14
                            Originally posted by Stan Mathews
                            Attachment is an example.
                            Hi Stan

                            Thank you for all the help.
                            I got the import going perfectly now.

                            Have a happy new year.
                            Many Thanks,

                            Peter

                            Comment

                            Working...
                            X