Announcement

Collapse
No announcement yet.

File_Read VS MvImport

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

  • RayYates
    replied
    As others have said, If you have a delimited text file, MvImport is the way to go. You can read the file directly into a Miva Data structure with very little extra effort, the speed difference is measurable but negligible, so it's a matter of using the right tool for the job. It also has the advantage of detecting formatting errors in the import file.

    It is possible to use MvImport to load the entire file into a single variable, like file_read(), by playing around with the delimiter.

    A downside to MvImport is that file must be in the mivadata folder, That could cause you to have to copy the file from the website or you must FTP it to the secure mivadata folder.

    In most case file_read() will be faster but as said, you have to do your own parcing. But If the data was created within miva to start with, there is a good trick to speed things up. Assuming the data is in a miva data structure, you can use

    <MvASSIGN NAME = "l.datastring" VALUE = "{ miva_array_serialize( l.mydatastructure) }"> and the use file_create() to write the file out all at once.
    Later you can reverse that process and use file_read() and <MvASSIGN NAME = "l.mydatastructure" VALUE = "{ miva_array_deserialize( l.datastring) }">

    For small to mid size data sets that do not change often, this is also an easy alternative to using a database table.

    Leave a comment:


  • wmgilligan
    replied
    Cool. So, I take out the Mustang for local runs to the flea market on a sunny day, but use the Benz when going on a long road trip.
    Makes perfect sense to me :-).

    Leave a comment:


  • Scot - ScotsScripts.com
    replied
    I did some local testing once with a largetext file, 40mb or so, and mvimport lost the speed test to file_read, but not by much. I use MvImport for line by line stuff and file_Read for everything else.

    Leave a comment:


  • wmgilligan
    replied
    Ok - so file_read requires more code to get info out of it - so thats a speed hit. But, when compared to import - is it faster?
    I should rephrase the question... assuming a text file with one line of text and no delimiters, does it matter which one is used, or is one actually better as far as the server is concerned (ie - optimization).

    As an old school guy, I am very familiar with mvimport - but wondering if simpler is better, or if newer is better.... I love an old mustang, but I'd prefer to ride in a new Benz.

    Leave a comment:


  • Kent Multer
    replied
    I'd say the best choice depends on what you want to do. For reading from a file containing lines of text, MvIMPORT is convenient to write with. It breaks the input file into lines, and can also break each line into fields if you want. It easily handles end-of-file and error conditions with help from MvIMPORTSTOP and MvIMPORTCONTINUE.

    file_read puts the entire contents of the file into a single string variable, with a single line of code. It's very simple; but if you have to write more code to parse the data, it might not be any faster or easier to use.

    HTH --

    Leave a comment:


  • wmgilligan
    started a topic File_Read VS MvImport

    File_Read VS MvImport

    Assuming a text file....
    What is faster - file_read or MvImport, and when is one preferred over the other?
Working...
X