cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

export project SQL database

export project SQL database

aFouraker
Occasional Contributor

Is it possible to export/import the sqlite database on the WebIQ app without manually copying the files in the file structure? For example to/from usb by pushing a button on the HMI? 

9 REPLIES 9

webiq-sk
Frequent Contributor

This is not possible. The database is constantly in use for recording data etc. Therefore you cannot switch the database at runtime. Also, for security reasons making it available from the frontend for reading and writing, essentially, could be a huge security issue.

To achieve this a complex logic would have to implemented first in the server and the frontend framework as well. 

Let me ask: what are you trying to achieve?

aFouraker
Occasional Contributor

I am writing and reading from the database using the built in javascript query manager to record some historic data. It is not continous but on event. I would like to be able to sporacially or on demand backup that database to a USB/SD card to save for historic purposes. 

webiq-sk
Frequent Contributor

The recommendation would be to export this data as CSV which you can either do using API queries on the WebIQ Server (this is fully documented in the WebIQ customer area) or wait until the next version 2.13 of WebIQ will be released (which is expected to be released within the next few weeks) which will make it a lot easier to export recorded data you can then write to a CSV file for example.

TN_X
Long-established Member

hello

is there any specific schedule for the next release WebIQ 2.13?

webiq-eg
Long-established Member

Hello,

the new WebIQ V2.13 Release will come soon, now in December. We have built huge improvements in the new release, e.g. completely new project handy. In addition, a completely new and very powerful trend display, comment function for alarms and trends and much more.
Unfortunately, the csv export had to be postponed to the next release in spring.
However, I will post an example code for the export function as LocalScript, but I need until mid-December to do so.
Many greetings
#webiq eg

TN_X
Long-established Member

Thank you. Looking forward to having your example code.

 

webiq-sk
Frequent Contributor

Please find the example UI Action below - this one exports the corresponding trend data for the current day.
itemsToRetrieve has to be set to an array containing the items you wish to export to CSV in the trend specified by its name in trendName:

 

/**
 * Custom UI-Action 'UA_ExportTrend'.
 */
(function() {
    var actions = shmi.pkg("visuals.session.userActions"); //get reference to userActions object
    /**
     * UI-Action 'UA_ExportTrend' implementation
     *
     * @params {any[]} parameters  configured ui-action parameters
     *
     */
    actions["UA_ExportTrend"] = async function(parameters) {
        const trend2 = shmi.visuals.core.TrendManager2,
            tsNow = new Date().getTime();
            itemsToRetrieve = ["DSaw", "DSin"], // Define items from the Trend to be retrieved here
            trendName = "Trend"; // The name of the trend to query

            // Set start to 00:00:00 on given timestamp (as an example)
            const tsStart = new Date(tsNow);
            tsStart.setHours(0);
            tsStart.setMinutes(0);
            tsStart.setSeconds(0);
            
            // Set end to 23:59:59 on given timestamp (as an example)
            const tsEnd = new Date(tsNow);
            tsEnd.setHours(23);
            tsEnd.setMinutes(59);
            tsEnd.setSeconds(59);

            // Get values from Trend2
            const values = await trend2.query(trendName, itemsToRetrieve, tsStart.getTime(), tsEnd.getTime(), 1000);
            let rows = [];
            values.forEach((result =>
                {
                    // Get all item values
                    result.values.item.forEach((dataRow => 
                        {
                            // Build csv row data
                            const tempArr = [result["item_alias"]].concat(dataRow);
                            rows.push(tempArr);
                        }
                    ));
                }
            ));
            // Build csv file and open download
            const csvContent = "data:text/csv;charset=utf-8,Item,TimeStamp,Value\n" 
                        + rows.map(e => e.join(",")).join("\n");
            var encodedUri = encodeURI(csvContent);
            window.open(encodedUri);
    };
}());

 

Feel free to adapt it to your needs.

webiq-sk
Frequent Contributor

@HmiGuide please see the screenshot I created from the editor (even the preview shows it wrong, i.e. converted to entities😞

webiqsk_0-1709883778012.png

Unfortunately this breaks the code as I was made aware of. I cannot post a fixed content here unless the bug has been resolved.

@ALL Please make the change above by replacing ":" by a colon as shown above after copying the code.

HmiGuide
Community Moderator
Community Moderator

@webiq-sk Thanks for the hint. I forwarded it to the administrator

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist