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

Native Indexes

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

  • Native Indexes

    I have been looking at the help files and found a script that would document the index structure of my application. Well that's what it implied. Part of the process was to create a text file of the structure, ready for the rainy day. the second part was the restore of the structures. Great idea. It came under the heading - Automatic Recovery of Indexes

    the bit that got me was the "The only type of table to examine is a "Native" table.". I can't find what thhis type of index is and why they are different from other types of indexes. Can some bright sole enlighten me....

    Part of the code is as below:-

    for i = 1 to count
    table_i = td.TableInfo[i].tablename

    'Check the table type. The only type of table to examine is a "Native" table. 'Use the .Set_Bottom_Message() method to update the progress dialog.

    sourceType_i = table.get_source_type(table.filename_get(table_i))
    td.TableInfo[i].sourceType = sourceType_i
    pDlg1.Set_Bottom_Message(table_i)
    if (sourceType_i = "Native") then

    'The get_index_definitions() function retrieves a text definition of a
    'table's indexes.

    td.TableInfo[i].indexDefinitions = get_index_definitions(table_i)
    else
    td.TableInfo[i].indexDefinitions = ""
    end if
    next i

    Needless to say this does not produce any output from my application.

    Thanks

    Paul

  • #2
    Re: Native Indexes

    This means that Alpha will only do this for it's own .dbf tables. It won't do it for other tables associated with the application, such as SQL tables, etc.
    -Steve
    sigpic

    Comment


    • #3
      Re: Native Indexes

      Originally posted by Steve Workings View Post
      This means that Alpha will only do this for it's own .dbf tables. It won't do it for other tables associated with the application, such as SQL tables, etc.
      Thanks for this I can now understand that part. Running the script does not produce any output though. Placing debug messages in the code suggests that it produces the index names. However, it does not produce any output to file. I have tried to follow it through but find it difficult to make sense of the sections. The total code is. Perhaps someone can show me where it is going wrong?

      ++++++++++++++++++++++++++++++++
      'Automatic recovery of indexes. Creates a text files of the index structures.
      '
      dim tables as C
      tables = a5.Table_Enum()

      'Create an array to hold the index information for each table.

      dim td as P
      dim count as N
      count = line_count(tables)
      dim td.TableInfo[count] as P

      ui_msg_box("Msg 1","Count "+count,UI_STOP_SYMBOL)
      'Initialize the array.

      td.TableInfo.initialize_properties("TableName",tables)

      'Create and display a progress dialog box with the WaitDialog .Create() method.

      dim pDlg1 as {waitdialog}
      pDlg1.Create(3,"Percent")
      pDlg1.Set_Title("Please Wait")
      pDlg1.Set_Message("Storing index information. Please wait...")
      ui_msg_box("Msg 2","Storing Index ",UI_STOP_SYMBOL)
      'Iterate through the tables, retrieving the index information for each.

      dim i as N
      dim table_i as C
      dim indexInfo_i as C
      dim sourceType_i as C

      for i = 1 to count
      table_i = td.TableInfo[i].tablename

      'Check the table type. The only type of table to examine is a "Native" table.
      'Use the .Set_Bottom_Message() method to update the progress dialog.

      sourceType_i = table.get_source_type(table.filename_get(table_i))
      td.TableInfo[i].sourceType = sourceType_i
      pDlg1.Set_Bottom_Message(table_i)
      if (sourceType_i = "Native") then

      'The get_index_definitions() function retrieves a text definition of a
      'table's indexes.

      td.TableInfo[i].indexDefinitions = get_index_definitions(table_i)
      else
      td.TableInfo[i].indexDefinitions = ""
      end if
      ui_msg_box("Msg 6","Index "+td.TableInfo[i].indexDefinitions,UI_STOP_SYMBOL)

      next i

      'Close the progress dialog. The a5.get_name() method returns the name of the current
      'database. The file.filename_parse() method constructs the path and filename for the
      'file that will store the index definitions.

      pDlg1.close()

      dim fn as C
      fn = file.filename_parse(a5.Get_Name(),"dpn") + ".txt"

      'Displays a message box (style:'OK Button', image: 'Stop symbol', id: 'msgpath').
      DIM SHARED msgpath_result as N
      DIM SHARED msgpath_OK_Button as L
      msgpath_OK_Button = .F.

      title_var = "Path"
      'Message is an expression. Need to evaluate the expression in the context of the current form.
      message_text_var = a5_eval_expression("=Var->fn",local_variables())
      msgpath_result=ui_msg_box(title_var,message_text_var,UI_OK+ UI_FIRST_BUTTON_DEFAULT+ UI_STOP_SYMBOL)
      'Test to see which button on the message box was pressed....
      SELECT
      CASE msgpath_result = UI_OK_SELECTED
      msgpath_OK_Button= .t.
      END SELECT

      'Use save_to_file() to save the variable that contains the index information to the
      'file on disk. Before you can save the variable, you have to convert it to a character
      'value using property_to_string().

      save_to_file(property_to_string(td,fn))

      ++++++++++++++++++++++++++++++++++++++

      thanks

      Paul

      Comment


      • #4
        Re: Native Indexes

        Paul:
        There are several errors in the code, as for example:
        dim td.TableInfo[count] as P: I wouldn't use a dot in the name. I think this is where your script stops execution. I am not sure if you did that in purpose or some sort of misunderstanding, but alpha is looking for a function called tableInfof[count] and since no such function exists, the script aborts
        td.TableInfo.initialize_properties("TableName",tables) "tableName" does not convey any structure
        table_i = td.TableInfo[i].tablename this does nothing since tablename is not a field nor a dot variable

        I didn't go further down the code. Rather than trying to fix this code, can you specify exactly what type of "output" are you looking for?
        I have a feeling you could achieve that with a much simpler code.

        Comment


        • #5
          Re: Native Indexes

          I didn't study your code, but below is a script I established a few years ago that did/does the job. I'm sure I could make some improvements in it, but it'll probably be of help. I don't even think I was the originator of this -- it may have even come from Selwyn when the feature was first introduced.

          Code:
          'get a list of all tables
          dim tables as c
          tables = a5.Table_Enum()
          dim td as p
          'create an array to hold the index information for each table
          dim count as n
          count = line_count(tables)
          dim td.TableInfo[count] as p
          'initialize the array
          td.TableInfo.initialize_properties("TableName",tables)
          
          'put up a progress dialog box.
          DIM pDlg1 as {waitdialog}
          pDlg1.Create(3,"Percent")
          pDlg1.Set_Title("Please Wait")
          pDlg1.Set_Message("Storing index information. Please wait...")
          
          dim i as n
          dim table_i as c
          dim indexInfo_i as c
          dim sourceType_i as c
          for i = 1 to count
              table_i = td.TableInfo[i].tablename
              'check the table type - we don't want to bother with shadow or linked tables - only care about Native tables
              sourceType_i = table.get_source_type(table.filename_get(table_i))
              td.TableInfo[i].sourceType = sourceType_i
              pDlg1.Set_Bottom_Message(table_i)
              if sourceType_i = "Native" then
                  td.TableInfo[i].indexDefinitions = get_index_definitions(table_i)
              else
                  td.TableInfo[i].indexDefinitions = ""
              end if
          next i
          
          'close the progress dialog
          pDlg1.close()
          
          dim fn as c
          fn = file.filename_parse(a5.Get_Name(),"dpn") + ".TableInformation"
          
          'save the variable that contains the information to the file on disk.
          'before you can save the variable, you have to convert it to a string value
          'using property_to_string()
          save_to_file(property_to_string(td),fn)
          -Steve
          sigpic

          Comment


          • #6
            Re: Native Indexes

            I named the script in my previous message Indexes_Store. Of course you'll also want Indexes_Restore. Herewith:

            Code:
            dim FixFlag as C
            FixFlag = "No"
            
            Begin:
            
            dim fn as c
            fn = file.filename_parse(a5.Get_Name(),"dpn") + ".TableInformation"
            if file.exists(fn) = .f. then
            	ui_msg_box("Error","Saved index information file not found.")
            	goto skip
            end if
            
            dim txt as c
            txt = get_from_file(fn)
            dim td as p
            'restore the array that contains the index information from the information stored on disk.
            property_from_string(td,txt)
            
            dim i as n
            dim count as n
            count = td.TableInfo.first_empty()-1
            
            If FixFlag = "Yes"
            	'put up a progress dialog box.
            	DIM pDlg1 as {waitdialog}
            	pDlg1.Create(3,"Percent")
            	pDlg1.Set_Title("Please Wait")
            	pDlg1.Set_Message("Checking indexes. Please wait...")
            end if
            
            dim tablesWithErrors as c = ""
            
            dim index_info_i as c
            dim table_i as c
            dim p as p
            
            for i = 1 to count
                index_info_i = td.TableInfo[i].indexDefinitions
                table_i = td.TableInfo[i].tablename
            	xbasic_wait_for_idle()
            	if FixFlag = "Yes"
               		pDlg1.Set_Bottom_Message(table_i)
               	else
            		statusbar.set_text("Checking indexes: " + table_i)
            	end if
                'only restore indexes if the table type is a native table
                if td.TableInfo[i].sourceType = "Native" then
                    P = indexes_match_defstring(table_i , index_info_i)
                    if p.missingIndexTags <> "" then
            '        	dim global vStored as c
            '        	vStored = index_info_i
                        tablesWithErrors = tablesWithErrors + table_i + crlf()
            				if FixFlag = "Yes" 
            					Create_Indexes(table_i,index_info_i)
            				end if
                    end if
                end if
            next i
            
            if FixFlag = "Yes"
            	'close the progress dialog
            	pDlg1.close()
            	statusbar.set_text("Rebuilding indexes, complete")
            	goto skip
            end if
            
            if tablesWithErrors <> "" then
               response = ui_msg_box("Notice","Index problems were found in the following tables: " + chr(10) + crlf()+ upper(tablesWithErrors) + chr(10) + \
            				"Would you like to re-run this process and automatically" + chr(10) + \
            				"rebuild indexes for the table(s) listed above?", UI_YES_NO + UI_QUESTION_SYMBOL)
            				
            	if response = ui_yes_selected
            		FixFlag = "Yes"
            		goto Begin
            	end if
            
            else
            	if "System" $ a_form_current
                	ui_msg_box("Notice","No index problems were found")
            	end if
            end if
            skip:
            -Steve
            sigpic

            Comment


            • #7
              Re: Native Indexes

              Thanks Steve,

              It works a treat. The code I presented came from the current help file. Looks like some work needs to be done here to stop confusing the poor amateurs like me.

              Anyone know where to direct corrections needed in the help file to? It is not really a bug....

              Paul

              Comment


              • #8
                Re: Native Indexes

                Originally posted by Paul Main View Post
                Anyone know where to direct corrections needed in the help file to? It is not really a bug....
                Paul
                Paul, at the bottom of every help page is an inconspicuous link called 'Comments'. This opens your email client addressed to documentation@alphasoftware.com.
                Tim Kiebert
                Eagle Creek Citrus
                A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

                Comment


                • #9
                  Re: Native Indexes

                  FWIW: The script Paul included in his second post works right up to the last line that says:
                  save_to_file(property_to_string(td,fn))

                  The use of the dot variables earlier in the script is correct although probably not necessary. (The presence of the square brackets indicates that it is an array, not a function call.)

                  There is no built-in function called "Save_to_file()". I can only assume that whoever wrote this either had their own user defined function or used this as a shortcut to indicate that the string could be saved to a file.

                  The real problem is in the "property_to_string(td,fn)" function call. If you check the Help file, the property_to_string() function only takes one argument. Therefore, property_to_string(td) is all that was necessary. (Possibly this Help info was created while the Property_to_string() function was still under development.)

                  It works correctly if you replace the save_to_file( property_to_string( td, fn ) ) with something like this:

                  result = property_to_string( td )
                  clipboard.Set_Data(result)
                  ui_msg_box( "", property_to_string( td ) )

                  Comment


                  • #10
                    Re: Native Indexes

                    My copy of the documentation refers to:

                    SAVE_TO_FILE()

                    Syntax

                    SAVE_TO_FILE( Data_String as C, Filename as C [, Append as L ] )

                    Argument
                    Description

                    Data_String
                    The data to save into the file.

                    Filename
                    The fully qualified name of a file.

                    Append
                    Optional. Default = .F. (overwrite file)

                    .T. = Append data.

                    .F. = Overwrite existing data.
                    Though I've never used it.
                    There can be only one.

                    Comment


                    • #11
                      Re: Native Indexes

                      I'll be danged! You are quite correct Stan. When the autocomplete in the code editor didn't show anything, I made the erroneous assumption that the function did not exist.

                      I tried it and it does indeed work.

                      That leaves only the error in the Property_to_string() call.

                      (Aside: And what ever happened to the autocomplete for Statusbar? It works in earlier versions of A5.)

                      Comment


                      • #12
                        Re: Native Indexes

                        Cal:
                        (The presence of the square brackets indicates that it is an array, not a function call.)
                        I am well aware of that, I do most of my programming with arrays. I don't see the wisdom of having a dot in the name of an array and secondly, to make things more confusing, the script says:
                        dim td as P
                        dim count as N
                        count = line_count(tables)
                        dim td.TableInfo[count] as P

                        and then says:
                        table_i = td.TableInfo[i].tablename

                        when the script gets to that part and starts reading td.tableinfo etc
                        remember you dim'd td first, now when you read td then dot alpha will look for a function at that point, more like when you say:
                        td=table.current()
                        td.field1=...

                        That's what I meant.

                        Comment


                        • #13
                          Re: Native Indexes

                          Originally posted by CALocklin View Post
                          I'll be danged! You are quite correct Stan. When the autocomplete in the code editor didn't show anything, I made the erroneous assumption that the function did not exist.

                          I tried it and it does indeed work.

                          That leaves only the error in the Property_to_string() call.

                          (Aside: And what ever happened to the autocomplete for Statusbar? It works in earlier versions of A5.)
                          I didn't really get into the whole of the code to see if the proper parameters for the built in function are supplied. It could still be that the usage in the posted script refers to a udf of the same name.
                          There can be only one.

                          Comment


                          • #14
                            Re: Native Indexes

                            Code:
                            "dim td as P
                            This creates a pointer named td.

                            Code:
                            dim count as N
                            count = line_count(tables)
                            dim td.TableInfo[count] as P
                            This creates an array of pointers within the td pointer.

                            Code:
                            table_i = td.TableInfo[i].tablename
                            This refers to a specific element (i) of the td.TableInfo array and assigns a value to its tablename property.

                            Alpha does not see "td." and look for a function. It will look for the element with the name that follows the dot. That could be any type of variable, including a function property.

                            I don't see the wisdom of having a dot in the name of an array
                            You could do this for many valid reasons. For example, you may want to pass around a pointer (td) that includes your array as well as other data. But in this case, it allows for the use of property_to_string() to save out a representation of all of the TableInfo elements.

                            Lenny Forziati
                            Vice President, Internet Products and Technical Services
                            Alpha Software Corporation

                            Comment


                            • #15
                              Re: Native Indexes

                              Lenny:
                              I am with you, but before you dim a sub-elemnet of the arry, don't you need to dim the array first? and once you dimmed the array as P, what's the point of dimming each sublement as P?

                              More like
                              dim x[i] as p
                              x.name[i]=table->field1.value or any p

                              Comment

                              Working...
                              X