Index of Functions ------------------ 1: check_Name_Length Function Name ( 1): check_Name_Length -------------------------------------------------------------------------------- 'Date Created: 19-Apr-2009 01:56:45 PM 'Last Updated: 19-Apr-2009 01:56:45 PM 'Created By : Ira J. Perlow 'Updated By : Ira J. Perlow FUNCTION Check_Name_Length AS C (TableList="" as c,Flags="" as c,Filename="" as C) 'DESCRIPTION: Checks Fields or Indexes for names longer than 10 in current database 'LIMITATIONS:I '========================================================================= ' Created by Computer Systems Design & Associates ' Copyright 2009 Computer Systems Design & Associates, All Rights Reserved ' http://www.csda1.com ' You may use this code at your own risk in whole or as a part. ' Personal or business use is fully permitted, but may not be distributed in any application ' Use in instructional materials is permitted if provided without modification as source '========================================================================= ' Check_Name_Length - Version 1.01 Release Date: 20090419 ' ' Syntax ' C Check_Name_Length([C TableList[,C Flags]]) ' ' Purpose: Checks Fields or Indexes for names longer than 10 in current database ' ' Input: TableList - Name of tables to process. Can be comma or CRLF delimited list ' Null or blank value processes all tables in current database ' ' Flags - ' F - return Field names >10 in length ' I - return Index names >10 in length ' If no F or I, then defaults to "FI" ' ' O - Open filename in text editor if filename is not blank ' Q - Quiet mode, No display box ' ' Filename - If not blank, then outputs results to a text file ' ' Output: Return's list of fieldnames and index names that the names exceed 10 in length ' (and thus use an extended name format in the data dictionary) ' ' Errors: Return's null "" on error or no table names ' ' Examples: ' ?Check_Name_Length() ' Returns and Displays all fields and indexes with names longer than 10 in current database ' ?Check_Name_Length("","Q") ' Returns all fields and indexes with names longer than 10 in current database with no display ' ?Check_Name_Length("","FQ") ' Just returns all fields with names longer than 10 in current database ' ?Check_Name_Length("Inventory,Invoice") ' Returns and Displays all fields and indexes with names longer than 10 in tables Inventory and invoice ' ' Notes: ' Ignores all non-existent tables specified or in database ' Tables specified without paths assume current database's path '====================================================================== ' Set default return value Check_Name_Length="" ' Get list of tables to process dim tbllst as c IF trim(tablelist)=="" ' blank parameter, so we process all tables. Sort in table name order tbllst=*for_each(x,word(x,2,","),sortsubstr(*for_each(x,file.filename_parse(x,"N")+","+x,a5.Table_Enum(1)),crlf())) ELSE ' non blank, so we translate any commas to CRLF() tbllst=alltrim(strtran(TableList,",",crlf())) END IF ' Get number of tables in list dim tblcnt as n tblcnt=line_count(tbllst) IF tblcnt<=0 ' Exit if no tables to process EXIT FUNCTION END IF ' Set option flags dim flg as c flg=ut(Flags) ' Set default flags F and I if neither IF (.not.("F" $ flg)).and.(.not.("I" $ flg)) flg=flg+"FI" END IF dim fldlst as c dim ndxlst as c fldlst="" ndxlst="" ' Process each table dim tblnam as c dim i as n For i=1 to tblcnt tblnam=word(tbllst,i,crlf()) IF file.filename_parse(tblnam,"E")=="" tblnam=tblnam+".dbf" END IF IF file.exists(filename_absolute(tblnam)) IF "F" $ flg fldlst=fldlst+*for_each(x,IF(len(trim(x))>10,str(len(trim(x)),2)+","+str(*counter(),4)+","+x+","+filename_relative(tblnam),""),Table.external_field_name_get(tblnam,"n")) END IF IF "I" $ flg ndxlst=ndxlst+*for_each(x,IF((ut(word(x,3,","))=="INDEX").and.(len(trim(word(x,1,",")))>10),str(len(trim(word(x,1,","))),2)+","+word(x,1,",")+","+filename_relative(word(x,2,",")),""),table.external_index_def_enum(tblnam,"n,p,t"+crlf())) END IF END IF next ' remove blank lines fldlst=remove_blank_lines(fldlst) ndxlst=remove_blank_lines(ndxlst) Check_Name_Length=fldlst+crlf()+ndxlst ' If not Quiet flag, then display in dialog box IF .not.("Q" $ flg) dim msg as c msg="" IF ("F" $ flg).and.(.not.(trim(fldlst)=="")) msg=msg+"Field Names - Length, Field Position, Name, Table"+crlf()+replicate("=",30)+crlf()+fldlst+crlf(2) END IF IF ("I" $ flg).and.(.not.(trim(ndxlst)=="")) msg=msg+"Index Names - Length, Name, Index File Name"+crlf()+replicate("=",30)+crlf()+ndxlst+crlf() END IF ui_msg_box("Fieldname and Indexes with Long Names",msg,UI_OK) END IF IF .not.(trim(filename)=="") dim filnam as c filnam=filename_absolute(trim(filename)) IF file.filename_parse(filnam,"E")=="" filnam=filnam+".txt" END IF dim msg as c msg="Database Application: "+IF(a5.Get_Master_Name()=="",a5.Get_Name(),a5.Get_Master_Name())+crlf()\ +"Generated on: "+dtoc(date())+crlf(2) IF ("F" $ flg).and.(.not.(trim(fldlst)=="")) msg=msg+"Field Names - Length, Field Position, Name, Table"+crlf()+replicate("=",30)+crlf()+fldlst+crlf(2) END IF IF ("I" $ flg).and.(.not.(trim(ndxlst)=="")) msg=msg+"Index Names - Length, Name, Index File Name"+crlf()+replicate("=",30)+crlf()+ndxlst+crlf() END IF save_to_file(msg,filnam) IF "O" $ flg sys_open(filnam) END IF END IF END FUNCTION End Function ( 1)---------------------------------------------------------------