App inventor 2 App: RowID Fusion Table - mysql

With App inventor 2 I got the ROWID number and I put the value in the "riga" variable. The Query is executing once and it writes correctely the data in the fusion table row, but then the query keeps on executing many times and the app writes hundred of times "400 Bad Request: Rowid must contains only numerals and underscores".
Why is it happening?

you created an endless loop
you should add a variable let's name it action, set it to rowid while you get the rowid and set it to update while you do the update
in the fusiontable controls got result event you need an if statement like this (pseudocode)
if action = "rowid"
then extract the received rowid and do the update
else print "update was successful"
btw. to get the rowid, you better split the result at \n (new line) to convert it into a list with 2 items, then select the second item to get the row id

Related

LOOKUP No Match Output

I have 5000 rows in source file with 11 columns with no duplicate rows
& I loaded all those rows in the destination table.
Now I inserted one new record and I tried performing lookup
In the lookup I mapped all the 11 columns and did not pass anything
and o/p of lookup (No match output) is passed to the destination.
But my output has 5000(previously loaded) + 5001 = 10001 rows
But I require that 1 new record to be inserted into destination table
Why is this happening ? Can someone tell me where I am wrong
Alternate : I tried using SCD but I couldn't figure it out which can be my business key
Columns are : Purchased Date,City,Investor Name,Investor City, Developer Name,Square feet,Area Purchased...
The way this usually works is this:
[Load Source File/Table] => [Lookup based on destination]
On matches (either ignore or send to update)
On no match (Insert the record)

How to update multiple records in same table using .AfterUpdate data macro without error "A data macro resource limit was hit."

I have a table tblItems with a list of inventory items. The table has many columns to describe these items, including columns for SupplierName, SupplierOrderNumber and PredictedArrivalDate.
If I order several new items from a supplier, I will record each item separately in the table with the same supplier name, order number and a predicted arrival date.
I would like to add a data macro, so that if I update the PredictedArrivalDate for one record, the value will be copied to the PredictedArrivalDate column of other records/items with the same SupplierName AND SupplierOrderNumber.
The closest I've got is:
SetLocalVar (MySupplierName, [SupplierName])
SetLocalVar (MySupplierOrderNumber , [SupplierOrderNumber ])
SetLocalVar (MyPredictedArrivalDate, [PredictedArrivalDate])
For Each Record in tblItems
Where Condition = [SupplierOrderNumber] Like [MySupplierOrderNumber] And [SupplierName] Like [MySupplierName] And [PredictedArrivalDate]<>[MyPredictedArrivalDate]
Alias OtherRecords
EditRecord
SetField ([OtherRecords].[PredictedArrivalDate], [MyPredictedArrivalDate])
End EditRecord
However, when I run this, only 5 records update, and the error log reports error -20341:
"A data macro resource limit was hit. This may be caused by a data
macro recursively calling itself. The Updated() function may be
used to detect which field in a record has been updated to help
prevent recursive calls."
How can I get this working?
I'm not one for using macro's to do anything, so I'd use VBA and recordsets/an action query to do the updating.
You can call a user-defined function inside a data macro by setting a local var equal to its result.
Access doesn't like data macros triggering themselves (which you are doing, you're using an on update macro and updating fields in the same table on a different record), because there is a risk of accidentally creating endless loops. Looks like you triggered a measure that's made to prevent this. I'd try to avoid that as much as possible.
Note: using user-defined functions inside data macros can cause problems when you're linking to the table from outside of Access (via ODBC for example).
This isn't a good solution (it's not a data macro), but it does work as a temporary fix.
I created an update query called "updatePredictedArrivalDate":
PARAMETERS
ItemID Long,
MyPredictedArrivalDate DateTime,
MySupplierName Text ( 255 ),
MySupplierOrderNumber Text ( 255 );
UPDATE tblItems
SET tblItems.PredictedArrivalDate = [MyPredictedArrivalDate]
WHERE (((tblItems.SupplierName) = [MySupplierName])
AND ((tblItems.SupplierOrderNumber) = [MySupplierOrderNumber])
AND ((tblItems.ID) <> [ItemID]));
On the PredictedArrivalDate form field .AfterUpdate event, I then added this macro:
IF [PredictedArrivalDate].[OldValue]<>[PredictedArrivalDate] Or [PredictedArrivalDate]<>""
OpenQuery (updatePredictedArrivalDate, Datasheet, Edit, [ID], [PredictedArrivalDate], [SupplierName], [SupplierOrderNumber])
I now have to remember to add this .AfterUpdate event to any other forms I create that amend that particular field.
If anyone has a better solution, please let me know.

Fetching data from database in a loop

Is there a logical way to get the data from sql periodically? I want to fetch a row from a table in my postgres DB, run some calculations on it in my python script, and fetch the second row of the data and go on with this procedure till all the calculation has been done.
enter image description here
In the table above, I would like to fetch each array of the travel time, do the calculations on it in my python code, and then go to the 2nd row and so on.
I believe your database library will provide you with a method for doing this. It might be called a cursor, a pointer or an iterator, which will have a method for fetching the next row from a query.
From https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-fetchone.html
cursor.execute("SELECT * FROM employees")
row = cursor.fetchone()
while row is not None:
print(row)
row = cursor.fetchone()

MySQL summary status table to store results of operations

I have a MySQL (5.6) database on my local workstation into which I routinely pull large datasets to perform analysis on. I have a separate SQL script for each dataset that imports the data and reformats it when needed (notably to convert date formats). In addition, I have other scripts that perform detailed analysis on the data.
For quality assurance, I would like to have a table named ImportLog that stores a record to capture the result of each import that is run. This table would look like the following:
ImportName DateRun RowsImported
---------- ------- ------------
ImportASR 2015-08-29 12902
ImportEAD 2015-08-30 18023
ImportHRData 2015-08-30 122376
The column definitions for ImportLog are as follows:
ImportName // the name of the script that is run
DateRun // the date that the script is run
RowsImported // the count of records imported in the run.
At the very end of each script would be the code to write one line to this table with the relevant data. For example, let's say that I ran the script named ImportASR on 8/29/2015 and it imported 12,902 records. At the end of the script, I want to append one record to ImportLog (like the first record in the table above) using something like this:
INSERT INTO ImportLog
VALUES("ImportASR",$DateRun,$RowCunt);
Every time I run one of the import scripts, it would add a row to the ImportLog table with the appropriate data.
My question is: How do I populate the $DateRun variable with the current date and the $RowCount variable with the row count of the newly imported ASR dataset? Or am I trying to approach this from the wrong angle?
First thing this morning I stumbled upon the answer to my problem; it was amazingly simple, and to my surprise it didn't need the use of any variables. The code to put at the end of each import script is something like:
INSERT INTO ImportLog
"Script: ImportASR",
SELECT NOW(),
(SELECT COUNT(*) FROM ASR_Full);
The InportLog table is initially defined like so:
CREATE TABLE LPIS_SearchMatchLog (
ImportName VARCHAR(25),
DateRun DATETIME,
RowCount INT
);
Hope this helps someone else!

How to display multiple records in java?

I have connected to one MySql table to fetch 1000 records that need to be displayed using JSP. I want to split my table into multiple tables (of size 50) which can be viewed by using next button on jsp page. How can I implement it?
String sql = "select * from people";
PreparedStatement statement = connection.prepareStatement(sql);
ResultSet result = statement.executeQuery();
while(result.next()) { // here i get 1000 records. how can i display these records on mulitple jsp pages?
// ... get column values from this record
}
Above gives 1000 records and I use a PreparedStatement.
Assuming you can fetch the complete table in JSP.
Just add one more param to the function returning the ROWS COUNTER
Add COUNTER to LIMIT clause in your QUERY.
Now you need to keep track of the COUNTER so Update the URL on click on next as
First Click - URL?pageCOUNTER=1
Second Click - URL?pageCOUNTER=2
Fetch the pageCOUNTER varaible from URL and pass it to your function as COUNTER
And so on. Keep getting you result.
OR USE JAVASCRIPT TABLE - http://www.datatables.net/