def importSVFile( filename, fieldSeparator = ",", dbid = @dbid, targetFieldNames = nil, validateLines = true )
      num_recs_imported = 0
      if FileTest.readable?( filename )
         if dbid
            getSchema( dbid )

            targetFieldIDs = []

            if targetFieldNames and targetFieldNames.is_a?( Array )
               targetFieldNames.each{ |fieldName|
                  targetFieldIDs << lookupFieldIDByName( fieldName )
               }
               return 0 if targetFieldIDs.length != targetFieldNames.length
            end

            useAddRecord = false
            invalidLines = []
            validLines = []

            linenum = 1
            IO.foreach( filename ){ |line|

               if fieldSeparator != "," and line.index( "," )
                  useAddRecord = true
               end

               if linenum == 1 and targetFieldNames.nil?
                  targetFieldNames = splitString( line, fieldSeparator )
                  targetFieldNames.each{ |fieldName| fieldName.strip!
                     targetFieldIDs << lookupFieldIDByName( fieldName )
                  }
                  return 0 if targetFieldIDs.length != targetFieldNames.length
               else
                  fieldValues = splitString( line, fieldSeparator )
                  if !validateLines 
                     validLines[ linenum ] = fieldValues
                  elsif validateLines and fieldValues.length == targetFieldIDs.length
                     validLines[ linenum ] = fieldValues
                  else
                     invalidLines[ linenum ] = fieldValues
                  end
               end

               linenum += 1
            }

            if targetFieldIDs.length > 0 and validLines.length > 0
               if useAddRecord
                  validLines.each{ |line|
                     clearFieldValuePairList
                     targetFieldIDs.each_index{ |i|
                        addFieldValuePair( nil, targetFieldIDs[i], nil, line[i] )
                     }
                     addRecord( dbid, @fvlist )
                     num_recs_imported += 1 if @rid
                  }
               else
                  csvdata = ""
                  validLines.each{ |line| 
                     if line 
                        csvdata << line.join( ',' ) 
                        csvdata << "\n"
                     end
                  }
                  clist = targetFieldIDs.join( '.' )
                  num_recs_imported = importFromCSV( dbid, formatImportCSV( csvdata ), clist )
               end
            end

         end
      end
      return num_recs_imported, invalidLines
   end
def importSVFile( filename, fieldSeparator = ",", dbid = @dbid, targetFieldNames = nil, validateLines = true )
      num_recs_imported = 0
      if FileTest.readable?( filename )
         if dbid
            getSchema( dbid )

            targetFieldIDs = []

            if targetFieldNames and targetFieldNames.is_a?( Array )
               targetFieldNames.each{ |fieldName|
                  targetFieldIDs << lookupFieldIDByName( fieldName )
               }
               return 0 if targetFieldIDs.length != targetFieldNames.length
            end

            useAddRecord = false
            invalidLines = []
            validLines = []

            linenum = 1
            IO.foreach( filename ){ |line|

               if fieldSeparator != "," and line.index( "," )
                  useAddRecord = true
               end

               if linenum == 1 and targetFieldNames.nil?
                  targetFieldNames = splitString( line, fieldSeparator )
                  targetFieldNames.each{ |fieldName| fieldName.strip!
                     targetFieldIDs << lookupFieldIDByName( fieldName )
                  }
                  return 0 if targetFieldIDs.length != targetFieldNames.length
               else
                  fieldValues = splitString( line, fieldSeparator )
                  if !validateLines 
                     validLines[ linenum ] = fieldValues
                  elsif validateLines and fieldValues.length == targetFieldIDs.length
                     validLines[ linenum ] = fieldValues
                  else
                     invalidLines[ linenum ] = fieldValues
                  end
               end

               linenum += 1
            }

            if targetFieldIDs.length > 0 and validLines.length > 0
               if useAddRecord
                  validLines.each{ |line|
                     clearFieldValuePairList
                     targetFieldIDs.each_index{ |i|
                        addFieldValuePair( nil, targetFieldIDs[i], nil, line[i] )
                     }
                     addRecord( dbid, @fvlist )
                     num_recs_imported += 1 if @rid
                  }
               else
                  csvdata = ""
                  validLines.each{ |line| 
                     if line 
                        csvdata << line.join( ',' ) 
                        csvdata << "\n"
                     end
                  }
                  clist = targetFieldIDs.join( '.' )
                  num_recs_imported = importFromCSV( dbid, formatImportCSV( csvdata ), clist )
               end
            end

         end
      end
      return num_recs_imported, invalidLines
   end
Add records from lines in a separated values text file, using a specified field name/value separator.

 e.g. importSVFile( "contacts.txt", "::", "dhnju5y7", [ "Name", "Phone", "Email" ] )

 If targetFieldNames is not specified, the first line in the file
 must be a list of field names that match the values in subsequent lines.

 If there are no commas in any of the field names or values, the file will be
 treated as if it were a CSV file and imported using the QuickBase importFromCSV API call.
 Otherwise, records will be added using addRecord() for each line.
 Lines with the wrong number of fields will be skipped.
 Double-quoted fields can contain the field separator, e.g. f1,"f,2",f3
 Spaces will not be trimmed from the beginning or end of field values.