Search code examples
c++mysqldatabasesqlitemosync

Sending data from client to SQL database (MoSync)


I sincerely apologize if this has been asked before, however I was unable to find a suitable answer that appeared similar to my current situation. I am developing an app with MoSync using the MAUI because of the same appearance across all platforms. I am running into issues with understanding MAHandles, as well as how to go about sending the SQLite information to a web address. The SQLite commands will then be converted to MySQL commands using a RedBean PHP script, and then sent to the permanent database.

My biggest concerns are 2 items:

1.Declaring connections that are usable through MAHandles (I have already gotten the SQLite commands working without using MAHandles, however declaring the database address in the resources.lstx still evades me)

2.Declaring MAHandles in general.

Also, I understand that strings are much more effective, however I disregard that fact due to the age of MAUI and it's capabilities appear much smoother when using char arrays.

I can provide additional clarification if needed so that I can help speed this process up.

Thank you ahead of time, and hopefully this will help others trying their hands at MoSync's immaculate product.


Solution

  • I have no experience with SQLite whatsoever, but I'm assuming handling SQLite commands is the job of your server-side application. To be clear, you are sending SQLite commands from your mobile app to a server-side app via a URL, correct? If you need help on this you should search "CGI". CGI is essentially a way to execute a server-side application with arguments via an http:// request.

    This means your app should have a manager that constructs a URL with the right SQLite commands based on the input events sent to your mobile app (buttons, text fields, etc).

    As far as Mosync goes, MAHandles can be used for many things including downloading.

    Take a look at the MAUtil::DownloadListener class on Mosync's doxygen pages. You will see that there are full descriptions of 5 pure virtual functions that you will need to implement. The bulk of your code will probably be in finishedDownloading( Downloader* dl, MAHandle data ). It is here that the MAHandle "data", will point to the beginning of the data segment that you downloaded.

    I read my data into a char* since I am downloading text.

    Here's a snippet:

    void MainScreen::finishedDownloading( Downloader* dl, MAHandle data )
    {
        char* mData = new char[ maGetDataSize( data ) + 1 ];
        memset( mData, 0, maGetDataSize( data ) + 1 );
        maReadData( data, mData, 0, maGetDataSize( data ) );
    
        // Destroy the store
        maDestroyObject( data );
    
        // Do something with mData;
    
    
    }
    

    Here's one example of setting the font of NativeUI::Widget text using an MAHandle:

    MAHandle font = maFontLoadDefault( FONT_TYPE_SERIF |
                            FONT_TYPE_MONOSPACE |
                            FONT_STYLE_NORMAL, 0, Dimensions::DIM_LIST_ELEM_FONT_SIZE );
    
    ListViewItem* items = new ListViewItem();
    items -> setFont( font );