예제 #1
0
//---------------------------------------------------------------------------
Database & Database::create(const utf8::String & name)
{
    utf8::String createSQL("CREATE DATABASE '" + (name.isNull() ? name_ : name) + "' ");
    if( dpb_.user().isNull() ) {
        createSQL += "USER 'SYSDBA' ";
    }
    else {
        createSQL += "USER '" + dpb_.user() + "' ";
    }
    if( dpb_.password().isNull() ) {
        createSQL += "PASSWORD 'masterkey' ";
    }
    else {
        createSQL += "PASSWORD '" + dpb_.password() + "' ";
    }
    if( dpb_.pageSize() <= 0 ) {
        createSQL += "PAGE_SIZE=1024 ";
    }
    else {
        createSQL += "PAGE_SIZE=" + utf8::int2Str((intmax_t) dpb_.pageSize()) + " ";
    }
    if( dpb_.fileLength() > 0 ) {
        createSQL += "LENGTH=" + utf8::int2Str(dpb_.fileLength() / dpb_.pageSize()) + " ";
    }
    createSQL += "DEFAULT CHARACTER SET " + dpb_.charset_;
    api.open();
    isc_db_handle newdb = 0;
    isc_tr_handle trans = 0;
    ISC_STATUS_ARRAY status;
    if( api.isc_dsql_execute_immediate(status,&newdb,&trans,0,(char *) createSQL.c_str(),(short) dpb_.dialect(), NULL) != 0 ) {
        ksys::AutoPtr<EDBCreate> e(newObjectV1C2<EDBCreate>(status,__PRETTY_FUNCTION__));
        if( !e->searchCode(isc_db_or_file_exists) ) {
            api.close();
            e.ptr(NULL)->throwSP();
        }
    }
    else {
        api.isc_detach_database(status,&newdb);
    }
    api.close();
    return *this;
}
예제 #2
0
파일: main.cpp 프로젝트: CIP-SSA/odktools
//Process a table in the manifest. This fuction is recursive
int procTable(QSqlDatabase db,QVariantMap jsonData, QDomNode table, QList< TfieldDef> parentkeys)
{
    QList< TfieldDef> keys;
    QList< TfieldDef> tkeys;
    QList< TtableKey> tableKeys;
    keys.append(parentkeys);

    QList< TfieldDef> fields;

    bool sqlCreated;
    sqlCreated = false;

    QString tableCode;
    bool tableSeparated;
    tableCode = table.toElement().attribute("mysqlcode");

    int recordIndex;
    int tkindex;


    if (tableCode == "af_rpt_secf_anmlsrcfd")
        log("Table:" + tableCode);

    //log(tableCode);

    QString tableXMLCode;
    tableXMLCode = table.toElement().attribute("xmlcode");

    bool genSQL;

    QDomNode child;
    child = table.firstChild();



    while (!child.isNull())
    {
        if (child.toElement().nodeName() == "field")
        {
            //We not process referenced fields because they come as part of the key
            if (child.toElement().attribute("reference") == "false")
            {
                TfieldDef field;
                field.name = child.toElement().attribute("mysqlcode");
                field.xmlCode = child.toElement().attribute("xmlcode");
                if (child.toElement().attribute("key").toStdString() == "true")
                    field.key = true;
                else
                    field.key = false;
                fields.append(field); //Append the field to the list of fields
            }
            genSQL = true;
        }
        else
        {
            sqlCreated = true; //To control more than one child table
            if ((tableXMLCode == "main") || (table.parentNode().toElement().tagName() == "ODKImportXML"))
            {
                mainTable = tableCode;
                if (genSQL == true)
                {
                    if (tableXMLCode == "main")
                        keys.append(createSQL(db,jsonData,tableCode,fields,keys,true));
                    else
                    {
                        // if we are processing the first table and is not main, this means that a repeat of one was used
                        // to store the cover data. Therefore the insert SQL must use both the information on root (jsonData)
                        // and the information on the repeat of one (map)
                        QVariantList result = jsonData[tableXMLCode].toList();
                        foreach(QVariant record, result)
                        {
                            QVariantMap map = record.toMap();
                            //debugMap(jsonData);
                            //debugMap(map);
                            keys.append(createSQL(db,jsonData,tableCode,fields,keys,true,map));
                        }
                    }
                    genSQL = false;
                }
                procTable(db,jsonData,child,keys); //Recursive call of a table from main
            }
            else
            {
                if (child.toElement().attribute("separated","false") == "true")