Help with Generator

Help with Generator

samsamtestsamsamtest Posts: 52Questions: 15Answers: 1
edited June 2018 in Free community support

Hi,
I have created and download the files when I have used the generator on the homepage.
The thing is, I don't need to create the tables. The database already exist. How can I change the generated file so it won't create a database and just get the data from it.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    In the PHP (or .NET or NodeJS) file for the table you will see something like:

    // The following statement can be removed after the first run (i.e. the database
    // table has been created). It is a good idea to do this to help improve
    // performance.
    $db->sql( "CREATE TABLE IF NOT EXISTS `test` (
        `id` int(10) NOT NULL auto_increment,
        `a` varchar(255),
        `b` varchar(255),
        `c` varchar(255),
        PRIMARY KEY( `id` )
    );" );
    

    Simply remove that. That said, it won't delete or replace an existing table!

    Allan

  • samsamtestsamsamtest Posts: 52Questions: 15Answers: 1

    Awesome, thanks.. I have another question.. If I have two primary keys how do I enter it in the Generator filed for primary key..
    Can I enter it like this ? bolag_id kundnr ore like this bolag_id, kundnr

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Generator doesn't support compound keys. For that you would need to edit the generated code a little.

    Allan

  • samsamtestsamsamtest Posts: 52Questions: 15Answers: 1

    Hi,
    Thanks for the help.
    I have been able to fix and creat it.

    If it’s okay I have another question,
    If I want to make a specific select question how do I do that..

    This is the select question i have created:

    select k.kundnr, k.kundnamn, sum(o.radsumma) as [radsumma]
    from kund k
    inner Join orderrad o on k.kundnr = o.kundnr
    where o.levstatus = 'Olevererad'
    group by
    k.kundnr, k.kundnamn

    Thanks
    Kinde Regards
    Sam

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Hi Sam,

    There is no option to do a group by in Editors server-side libraries at the moment I'm afraid.

    You can make the SQL query directly using $db->sql('...')->fetchAll(), but as I say, that is not supported by the Editor libraries.

    Allan

  • samsamtestsamsamtest Posts: 52Questions: 15Answers: 1

    okay, Thanks for the help

  • samsamtestsamsamtest Posts: 52Questions: 15Answers: 1

    I wonder If I don't use a the generator, Is it hard to do a select question,, ?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    The thing to remember about Generator is that it is a quick start tool only. To get the most out of Editor and DataTables you need to code with their options and APIs. This example will help and also the manual documentation that it links to.

    Allan

This discussion has been closed.