Announcement

Collapse
No announcement yet.

Database

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

  • Imagine Programming
    replied
    Originally posted by BioHazard View Post
    @Imagine Programming
    You created MemoryEx for the sole purpose of confusing me, right?
    Admit it - it's all part of your evil plan to take over the world!



    Listen, just out of curiosity, is MemoryEx in any way related to AMSWaves' old AMSWMemory plugin? eg. Is it something you inherited and then redeveloped? Not that it's important (shamefully, I can't understand his plugin either). Just curious about that one.
    Nope, in no way is it related to AMSWaves' plugin (it's built from scratch). I remember starting MemoryEx because AMSWMemory was not maintained anymore. I then took the opportunity to add pretty much everything you could need when talking to the lower-level systems outside of Lua and AMS.

    So yeah, it's purposefully built to confuse people haha!
    Last edited by Imagine Programming; 01-05-2019, 10:27 AM.

    Leave a comment:


  • Nerdcu
    replied
    Ok I will experiment with that plugin seems promising, do not worry I will not ask for more help on my project until I have completely fixed it, including its format, I have a lot of work but I am glad because I am going to improve my project a lot thanks to you, and I am learning more in these days in the forum than in a year by myself. Thank you!

    Leave a comment:


  • BioHazard
    replied
    Originally posted by Nerdcu View Post
    I have the best disposition to send you my project.apz but it is all written in the same way. With variables in Spanish and comments in Spanish... I could send it if you wish...
    No, please don't. I personally won't even look at it again until everything is in English. So please invest the time to do that before reposting. It would also be very helpful if (when doing the translation) you reformatted your code properly, too. That is to say, indent your code correctly (by tabbing after keywords and control-structures and by using whitespace appropriately) so the whole thing becomes more readable. Please read this post before proceeding: Code Formatting under the section titled, Lesson #3: Commenting, White-space and Indenting and Posting Code.


    The only way I can see that I can explain myself better before fixing the project is by showing the value that each index of my data table contains at run time
    Best you just upload the project.apz (in English please). Add sufficient 'commenting' to the code, to re-explain the problem you're experiencing.

    Judging by the contents of your attached datasets, you might actually do better with RizlaUK's DatabaseEx plugin. As far as database plugins go, it has very basic functionality. But may give you the data control you need without the complexity required of SQLite. A link to that plugin was already created in an earlier thread so I won't repost it here - just go to the thread in question: HERE


    I'm sorry as you see I still do not know how to use the code button and others...
    The Code button is the one highlighted in red. And the Quote button is the one immediately to the left of it.




    ..............................................

    @Imagine Programming
    You created MemoryEx for the sole purpose of confusing me, right?
    Admit it - it's all part of your evil plan to take over the world!



    Listen, just out of curiosity, is MemoryEx in any way related to AMSWaves' old AMSWMemory plugin? eg. Is it something you inherited and then redeveloped? Not that it's important (shamefully, I can't understand his plugin either). Just curious about that one.

    Leave a comment:


  • Nerdcu
    replied
    I'm sorry as you see I still do not know how to use the code button and others, I admit that I am like a big disaster. When I published this post, I had not seen the post of Imagine Programming, so now I'm going to study it. Thank you all.

    Leave a comment:


  • Nerdcu
    replied
    First of all, thank you very much for taking part of your time to help me, I really appreciate it because I really need it a lot. I would like you in no way to feel that you have wasted your time analyzing my code disaster, because everything you have explained to me has been very useful to me and I have learned a lot with everything you have sent me, knowledge that can not be acquired only by using the AMS help and the Lua 5.1 Reference Manual, only with the help of experienced programmers like you, Imagine Programming and many others that will be in this forum.
    I have the best disposition to send you my project.apz but it is all written in the same way. With variables in Spanish and comments in Spanish, as well as a great mix of native AMS and Lua functions, I think it would be just as confusing, but I could send it if you wish and even upload the created software to the cloud and share the link so that download and examine it.
    The project started with AMS only but then I had to go to Lua because there were things that AMS did not allow me to do (or at least I thought) and did not have plugins or other external help or someone with knowledge. That's why the project resulted in that great mix. For this reason, I have proposed to completely rewrite it in English and with native Lua. With the great help that you have given me now I understand that it will be much more optimized and less prone to errors.
    It is true that at some point I said that it contained functions, but no, it was just a way of saying that the table was heterogeneous, bad way of expressing myself.
    That is why I started this topic in of the database, because I set out to create a new database that contains both elements, simple strings and paragraphs because now I have them separately, the project also contains images and pdf files, but I understand that in a table you can only refer to them.
    In fact, I was pretty sure I was not going to explain myself well, but you understood the essence, when you send me this code.


    [QUOTE]
    local str = [[ tbl = { 'January', 'February', 'March' } ]] assert(loadstring(str))(); for k,v in pairs (tbl) do Dialog.Message("Table Values", v); end
    ​[\QUOTE]
    ​​​​​​
    The only way I can see that I can explain myself better before fixing the project is by showing the value that each index of my data table contains at run time, and that's what I want to know if there is any way to save it as a base data in the same way, without the element t [3] losing its paragraph value, because it does so if I save the table as a text, if I still can not explain myself then I will not waste any more your time and I will return the subject when I have fixed everything. Here it is the values:

    [CODE] t[1] = "Se vende casa deplaca de 3 cuartos portal delantero y trasero tanque elevado, frente a la circunvalacion Llamar al 54640809 Villa Clara"
    t[2] = "55008337: Quien tiene un iPhone x en venta??. Villa Clara."
    t[3] = [[Habano's bar(santa clara)
    OFERTA DE EMPLEO Y NEGOCIO"
    Necesitamos un cocinero con disponibilidad a tiempo completo con experiencia en cocina al grill
    Condicionesersona emprendedora y con minimo de conocimiento en marketing
    Email:[email protected]
    Localidad:santa clara]]


    [\ CODE]

    t [3] is a paragraph, I do not know if I represented it correctly.
    These elements will be displayed in a Rich Text object.
    My dataset is charged with a text file like the one I attached.
    I am very grateful to you. Thank you.
    Attached Files

    Leave a comment:


  • Imagine Programming
    replied
    Here's another solution of saving a table as is using MemoryEx, however this is not a good solution for large tables. MemoryEx.Table was designed for small-ish values to synchronize processes / routines. MemoryEx.Table in conjuction with Lua's io file functions can be used to dump a binary format to disk and read it back later.

    Attached Files

    Leave a comment:


  • BioHazard
    replied
    Originally posted by Nerdcu View Post
    ... Someone knows if it is possible to save in the HDD, a heterogeneous table that exists at runtime, which contains variables, functions, registers....
    It's not entirely clear what you're asking here - because in your very next post you contradict yourself:

    The table only contains two values, simple strings and paragraphs, it does not contain functions and it is necessary to do searchs in it ...
    And in another thread on this matter you asked:

    Does anyone know another way to physically save a table without the variable losing its value as a paragraph?
    You need to be more clear but I'll hazard a guess that your concern is that your dataset contains a table that's actually getting propagated as a string? I'm really not entirely clear on what you're actually asking here - but if this is the case, you can still retrieve the table values of a propagated string, by using Lua's loadstring() function to create an executable lua chunk: Eg.
    .
    Code:
    local str = [[
    tbl = {
        'January',
        'February',
        'March'
    }
    ]]
    
    assert(loadstring(str))();
    for k,v in pairs (tbl) do
        Dialog.Message("Table Values", v);
    end

    Also, have a look in the main AMS Scripts folder (ie. AMS >> Gallery >> Scripts) at the DelimitedStringFunctions script, you'll find functions to both:
    • return a numerically indexed table with string elements (ie. breaks up a delimited string into a table)
    • return a delimited string of table elements (ie. makes a table into a delimited string).


    IP has already asked you to share an example of the table data you're working with but you haven't done that yet - which makes it difficult to determine whether a database is better suited to your needs.

    You've indicated how you're searching through the dataset, but why are you mix-n-matching native Lua calls with AMS functions so haphazardly? For example, you indicate an understanding of Lua's string.gsub() function but then revert back to the inferior AMS version of String.Replace(). And ditto with string.gmatch(). So you indicate an understanding of the 2 most powerful functions in the Lua string library. And yet, go back and forth laboring through the various AMS string functions, unnecessarily. Why not just apply native Lua wherever possible - and achieve the same result with half the overhead?

    Look, there's a number of custom functions you can use when working with datasets expressed as textfiles - each of which can simplify things greatly and provide you with a greater degree of consistency in the application of your code. I've zipped and attached these for you, in the form of a Lua script (which you can load directly into Globals if so desired). But basically, it includes the following customized functions:
    • TextFile_CountLines
    • TextFile_FindLine
    • TextFile_GetLine
    • TextFile_InsertLine
    • TextFile_DeleteLine
    I believe these functions were actually compiled as a plugin at some stage - but I don't have it and you don't really need it - as these can be called directly from Globals.

    .................................................. ............


    Your code is very hard to follow and to make enough sense of, to get a decent overview of what it is you're trying to achieve. It'd be much better if you just uploaded your project.apz so we can see it in context with the dataset you're working with. Help can be supplied more efficiently that way.

    I'm sorry but here if there are several comments in Spanish that I had time to fix but if necessary I do it and I send it back to you
    It's not just the comments that are in Espanol, plenty of your variables are, too. And that's what makes it so hard to follow. So yes, please fix that first! If someone's donating time to help you ... then make the time to ensure it's ALL in English!

    In the meantime, here's some tips for you to work with. As said, it's difficult at this stage to get a proper overview of what you want, and I have a only a vague sense of what you're trying to do. But you do seem to have some grasp of native Lua - so these might (or LOL, might not) be helpful:

    When interacting with datasets within textiles, correct application of the string.gmatch() and string.gsub() functions can save you a lot of work. These 2 functions alone can replace a lot of the inefficiency inherent within AMS's string library. And when combined with with pattern-matching, can be great for finding strings, substrings and values within your dataset.

    So then, regarding your use of string.gsub() ...
    Code:
    for til = 1, 12, 1 do
        sintilde = string.gsub(sintilde, voccontil[til], vocsintil[til])
    end
    It's unnecessary to enter gsub into a countloop. The gsub function has an optional 4th parameter (an integer value representing the number of substitutions). Eg.
    Code:
    -- Longhand Version:
    local a = "blue sky, blue water, blue mood";
    local b = "blue";
    local c = "black";
    
    sReturn = string.gsub(a, b, c, 3)
    Dialog.Message("Longhand gsub", sReturn);
    
    -- Shorthand Version:
    local a = "blue sky, blue water, blue mood";
    local b = "blue";
    local c = "black";
    
    sReturn = a:gsub(b, c, 3)
    Dialog.Message("Shorthand gsub", sReturn);
    And just an example here of the correct use of string.gmatch():
    Code:
    -- Longhand Version:
    local a = "blue sky, blue water, blue mood";
    local b = "blue";
    
    for k in string.gmatch (a, b) do
        Dialog.Message("Longhand gmatch", k);
    end
    
    
    -- Shorthand Version:
    local a = "blue sky, blue water, blue mood";
    local b = "blue";
    
    for k in a:gmatch (b) do
        Dialog.Message("Shorthand gmatch", k);
    end
    You can also use string.gmatch to iterate across a string to grab its individual pieces. It's called 'tokenizing a string'. Like this:
    Code:
    local s = "Tokenize this string with gmatch";
    for x in string.gmatch(s,'%w+') do
        Dialog.Message("", x);
    end
    The AMS Table.Count() function that you're using can be replaced with the more effecient native Lua equivalent of table.getn() or its shorthand version: #t
    Code:
    local t = {
        "Germany",
        "France",
        "Russia",
        "USA"
    };
    
    local i = table.getn(t);  -- longhand version
    Dialog.Message("Count", i);
    
    local i = #t; -- shorthand version
    Dialog.Message("Count", i);

    And if you need to count the number of times a substring occurs within any given string or dataset, you can use this function:

    Code:
    --############################################################################################
    --##                                                                                        ##
    --##  FUNCTION:        countSubString(sMain, sSub)                                          ##
    --##  PURPOSE:        Counts all occurences of a specified Sub-String in any MainString     ##    
    --##  RETURNS:        Number value representing instances found in main string              ##
    --##                If no Instances found (or error occurs), 0 is returned                  ##
    --##                Nb. Search is case-insensitive                                          ##
    --##                                                                                        ##
    --############################################################################################
    
    function countSubString(sMain, sSub)
        local nLast = 1;
        local nInstances = 0;
        local nFoundInstance = 0;
        local nLength = String.Length(sSub);
        while not (nFoundInstance == -1) do
            nFoundInstance = String.Find(sMain, sSub, nLast, false);
            if not (nFoundInstance == -1) then
                nInstances = nInstances + 1;
                nLast = nFoundInstance + nLength;
            end
        end
        return nInstances;
    end
    
    -- Example Useage
    local string = "blue sky, blue water, blue mood";
    local substring = "blue"
    Dialog.Message("Count", countSubString(string, substring));

    ... And to return the positions of each occurence of that substring, you can use this function:

    Code:
    --############################################################################################################
    --##                                                                                                        ##
    --##  FUNCTION:  findSubString                                                                              ##
    --##  PURPOSE:  Finds all occurences of a specified Sub-String in any MainString and return their postion   ##
    --##  RETURNS:  Number value representing position of substring                                             ##
    --##                                                                                                        ##
    --############################################################################################################
    
    function findSubString(a, b)
        local int = #a;
        local num = 1;
        local pos = "";
        while num < int do
            local x = String.Find(a, b, num, false);
            if x > -1 then
                pos = pos .. x .."\r\n";
                num = x + 1;
            else
                num = num + 1;
            end
        end
        return pos
    end
    
    -- Example Useage:
    local mString = "blue sky, blue water, blue mood";
    local sString = "blue";
    Dialog.Message("SubString found at:", findSubString(mString, sString));
    Nb.
    In future, please use the forum's CODE button to display your code properly, so it's separate from the body your post. It's very difficult for us to read like this.
    Attached Files

    Leave a comment:


  • Nerdcu
    replied
    My table is t and this is the way I load the data, first a loop for the simple strings and then another loop to load the paragraphs, as you will see without I have finished the loop to load the paragraphs, although basically it is the same.

    tblcuba = TextFile.ReadToTable ("E:\\Docs BD\\cuba y categorias\\tblcuba.txt");
    filtblcuba = Table.Count(tblcuba);


    for h = 1, filtblcuba, 1 do

    a = tblcuba[h]--o strin read to table para parrafo

    t[h] = a

    end

    va = Table.Count(t)

    v = va + 1

    t[v] = TextFile.ReadToString("E:\\Docs BD\\cuba y categorias\\parrafo\"..namep);

    and this is my search routine in the table, it must be quite bad because it was the first thing I did but it works well, it is a search that pretends to be similar to that of a web, here the table t would be tblcubafull

    for til = 1, 12, 1 do
    textbus = string.gsub(textbus, voccontil[til], vocsintil[til])
    end


    if (textbus == "") then
    xxx = 1
    Application.ExitScript();
    end

    zisestring = String.Length(textbus);


    for poi in string.gmatch(textbus, " ") do--busqueda de espacios
    espa = espa + 1
    espaout = espa - 1--seria lim ite de repeat
    end

    if zisestring == espa-1 then
    xxx = 1
    Application.ExitScript();
    end

    textbus = String.Replace(textbus, textbus, textbus.." ", false);
    espa = 1
    for poi in string.gmatch(textbus, " ") do--busqueda de espacios
    espa = espa + 1
    espaout = espa - 1--seria lim ite de repeat
    end
    if (textbus == "") then Application.ExitScript()
    end
    zisestring = String.Length(textbus);
    repeat
    espacio = String.Find(textbus, " ", 1, false);
    if espacio == 1 then
    textbus = String.TrimLeft(textbus, nil);
    end
    espacio = String.Find(textbus, " ", 1, false);
    tblxx = String.Mid(textbus, 1, espacio-1);
    textbus = String.TrimLeft(textbus, tblxx);
    if tblxx ~= "" then
    tblabuscar[xz] = tblxx
    end
    xz = xz + 1;
    oleo = oleo + 1
    until oleo == espaout


    tblabuscarsinrep = {};
    endtblxx = Table.Count(tblabuscar);
    local v = 1
    local y = 1
    local i = 1
    local nocero = 1

    for v = 1, (endtblxx) do
    for y = v + 1, endtblxx do
    comparacion = String.CompareNoCase(tblabuscar[v], tblabuscar[y]);
    nocero = nocero * comparacion
    end
    if nocero ~= 0 then
    tblabuscarsinrep[i] = tblabuscar [v];
    i = i + 1;
    end
    nocero = 1;
    end
    endsinrep = Table.Count(tblabuscarsinrep)


    find = 0
    sumando = 0
    tblresult = {}
    cdr = 1

    local t = 0;



    for vb = 1, filtblcubafull, 1 do

    sintilde = tblcubafull[vb]

    for til = 1, 12, 1 do
    sintilde = string.gsub(sintilde, voccontil[til], vocsintil[til])
    end

    for nm = 1, endsinrep, 1 do

    sicompu = String.Find(sintilde, tblabuscarsinrep[nm], 1, false);

    if sicompu > 0 then
    find = find + 1

    end
    end

    if find == endsinrep then
    tbl[cdr] = tblcubafull[vb]
    cdr = cdr + 1
    end
    find = 0
    end




    local t = 0;

    if tbl[1] == nil then
    Dialog.Message("", "No Hay Resultados Para Su Busqueda");
    cuba = 1
    Application.ExitScript();
    end




    tabla = tbl
    filtabla = Table.Count(tabla);

    Page.Jump("con grid");

    I'm sorry but here if there are several comments in Spanish that I had time to fix but if necessary I do it and I send it back to you

    Leave a comment:


  • Imagine Programming
    replied
    Originally posted by Nerdcu View Post
    Thanks for your willingness to help me. The table only contains two values, simple strings and paragraphs, it does not contain functions and it is necessary to do searchs in it. The data set can reach up to 40,000 elements. Please, if I have not yet been clear, do not hesitate to ask me again, I have little experience.
    Could you share an example table in here? Also, could you also show how you are searching through the dataset? I'm trying to determine if you need a database (like SQLite) or a simple written file

    Leave a comment:


  • Nerdcu
    replied
    Thanks for your willingness to help me. The table only contains two values, simple strings and paragraphs, it does not contain functions and it is necessary to do searchs in it. The data set can reach up to 40,000 elements. Please, if I have not yet been clear, do not hesitate to ask me again, I have little experience.

    Leave a comment:


  • Imagine Programming
    replied
    A couple of questions:
    1. What data do you have in the table? Only strings, booleans, numbers and subtables? Functions as well? Storing / loading functions is dangerous
    2. Does the table have to be searched?
    3. How big is the dataset?

    Leave a comment:


  • KELLYRUTH
    replied
    Todo es posible en esta vida

    Leave a comment:


  • Nerdcu
    started a topic Database

    Database

    Hi. I want to reformulate my question. Someone knows if it is possible to save in the HDD, a heterogeneous table that exists at runtime, which contains variables, functions, registers. The ultimate goal is to load it from a software as a database, thats why I need to save it physically. Thank you.
Working...
X