How can I get the number of rows that will be returned by a sql for a Report Studio report at run time in Javascript? The purpose is to terminate the report as it exceeded the row limitation and notify the user an alert message to re-enter prompts that would reduce the volume of data. Doing so the users will be able to run the report with new prompts without having to re-run the report.
I could find couple of options to limit the maximum rows returned but all they do is terminate the report with an error.
I can suggest another solution. Without Javascript.
Create condition block based on row count.
Add a Query Item with value
Count([Your field]) for report
Add Singleton with your query and this new Query Item.
Set Query property for Page to your main query.
Set Processing property for your main query to "Limited local"
Add Conditional Block with new variable e.g. boolean. Value
[Your query].[Your new field] > 1000
Put you report on a "No" page of conditional block, and a message about row limitation on a "Yes" page.
This solution will work even if you use Excel output.
You can try to add HTML Item to row. Source Type = Report Expression
Put inside
'<script language="javascript">
if ('+number2string (RowNumber ())+'>500){
//Put here code that stops page loading
}
</script>'
But, I don't know how to stop load Cognos page. Usual ways don't work.
You can hide or erase a part of report (whole List), but Cognos load all data anyway.
Related
I have an insert query in oracle apex, sometimes the data are not inserted because of different reasons (for example writing a text in number field). is there a way to display an error message that check if data is inserted in the database or not?
This is how this can be done for a page process of type pl/sql. Example is on the sample dept table.
Create 2 page hidden page items: P48_SUCCESS_MESSAGE and P48_ERROR_MESSAGE
In the page process that does the update use the following code
DECLARE
e_invalid_insert exception;
BEGIN
INSERT INTO dept(dname, loc) VALUES (:P48_DNAME,:P48_LOC);
:P48_SUCCESS_MESSAGE := 'Insert succesful';
EXCEPTION WHEN OTHERS THEN
-- below code will also show database error, adjust for your requirements
:P48_ERROR_MESSAGE := 'Insert failed:' ||SQLERRM;
RAISE e_invalid_insert;
END;
For the attribute "Success Message" of the page process put &P48_SUCCESS_MESSAGE., For the attribute "Error Message" of the page process put &P48_ERROR_MESSAGE.
Check the help text for "Error Message" and "Success Message" for available substitution strings.
Note, you state sometimes the data are not inserted because of different reasons (for example writing a text in number field). As a developer you can put in validations to ensure that the data is correct before the insert process is executed. If a validation fails, the insert statement will not be executed (and it should not be executed).
As a follow-up to my last question, I have run into another problem. I am making a project on google homepage replica. The aim is to show search results the same as google and store the search history on a database. To show results, I have used this javascript:-
const q = document.getElementById('form_search');
const google = 'https://www.google.com/search?q=';
const site = '';
function google_search(event) {
event.preventDefault();
const url = google + site + '+' + q.value;
const win = window.open(url, '_self');
win.focus();
}
document.getElementById("s-btn").addEventListener("click", google_search)
To create my form, I have used the following HTML code:-
<form method="POST" name="form_search" action="form.php">
<input type="text" id="form_search" name="form_search" placeholder="Search Google or type URL">
The terms from the search bar are to be sent to a PHP file with the post method. I have 2 buttons. Let's name them button1 and button2. The javascript uses the id of button1 while button2 has no javascript and is simply a submit button.
The problem is that when I search using button1, the search results show up but no data is added to my database. But when I search using button2, no results show up( obviously because there is no js for it) but the search term is added to my database. If I reverse the id in javascript, the outcome is also reversed. I need help with making sure that when I search with button1, it shows results and also saves the data in the database. If you need additional code, I will provide it. Please keep your answers limited to javascript, PHP, or HTML solutions. I have no experience with Ajax and JQuery. Any help is appreciated.
Tony since there is limited code available so go with what you had stated in your question.
It is a design pattern issue not so much as so the event issue.
Copy pasting from Wikipedia "software design pattern is a general, reusable solution to a commonly occurring problem within a given context in software design. It is not a finished design that can be transformed directly into source or machine code. Rather, it is a description or template for how to solve a problem that can be used in many different situations. Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system."
So here is how things play out at present;
forms gets submitted to specific URL i.e. based on action attribute
Requested page gets Query sting in php and lets you play around with it
then from there on .....
3. either you get results from database and return response
4. or you put search request into database and return success response
Problem statement
if its 3 then search request is not added to database if its 4 then results in response to search request are not returned.
Solution
you need to combine both 3 and 4 in to one processing block and will always run regardless of the search query is.
So our design pattern could use mysql transaction so whole bunch of queries would run a single operation example
$db->beginTransaction(); // we tell tell mysql we will multiple queries as single operation
$db->query('insert query');
$results= $db->query('search query');
$db->commit(); // if we have reached to this end it means all went fine no error etc so we commit which will make database record insert query into database. If there were errors then mysql wont record data.
if($results) {echo $results;} else {echo 'opps no result found';}
slightly more safe version
try {
$db->beginTransaction(); // we tell tell mysql we will multiple queries as single operation
$db->query('insert query');
$results= $db->query('search query');
$db->commit(); // if we have reached to this end it means all went fine no error etc so we commit which will make database record insert query into database. If there were errors then mysql wont record data.
if($results) {echo $results;} else {echo 'opps no result found';}
} catch (\Throwable $e) {
// An exception has been thrown must rollback the transaction
$db->rollback();
echo 'oho server could not process request';
}
We have effectively combined two query operation into one always recording into database and always searching in database.
I'm using diffbot to scrape products. It gets things right on most sites, and if it doesn't the custom API usually allows me to easily tweak until correct. However there are a few cases that are baffling me.
I know diffbot doesn't execute javascript in the custom API preview window, but for the product endpoint, it should always execute it when a request is made to the API (e.g. from the diffbot client in a Python shell).
Foot asylum
For products on this website, e.g. https://www.footasylum.com/hugo-boss-three-pack-tshirt-103678/, the offerPrice field is empty. I can see the price is in a div#priceFrm, so I try to edit and add a custom selector on that field to this effect. However even when making a new API call from the Python shell, the response is 'offerPrice': ''.
This price is obviously being added by Javascript, but why can't diffbot deal with that? What can I do about it?
I can also see the price I want can be found in some JSON data inside a <script>. Normally I could just scrape it from there, with //script[contains(text(), "dataLayer")]/text() followed by a regex. However in another diffbot custom field I defined a selector script:contains(dataLayer) and even this is blank.
Any ideas on getting the price from this product with diffbot?
Nike
I'm also trying to get the price from https://www.nike.com/gb/t/flyknit-trainer-shoe-GBXjsV/AH8396-600
The first problem is the preview window of custom API just gives a 500 error weirdly.
Next I edit the offerPrice field with a custom selector of div[data-test=product-price], however this field doesn't hit anything - even when called from client in Python shell.
Footlocker
Finally on this site https://www.footlocker.co.uk/en/p/jordan-1-flight-2-men-shoes-6671?v=314100340604#!searchCategory=all diffbot cannot seem to get product image.
The images are loaded by "scene7", and with XPATH can be found with //div[#class="s7thumb"][#data-namespace="s7classic"]/#style and then parsing out the "background-url".
I tried to at least get the style attribute with diffbot using the selector div.s7thumb div[data-namespace=s7classic] and then adding the Attribute filter "style", but again nothing at all is returned.
In some cases, specific rendering of certain elements will be blocked either by Diffbot's renderer or by a target site's anti-block measures. That's why Diffbot has X-eval functionality which lets you add custom JavaScript into calls which will get executed on a target site, as if running from the console. In this case, something like the following helps:
function() {
start();
setTimeout(function() {
price = document.querySelector("[itemprop="
Offers "] [itemprop="
price "]");
currency = document.querySelector("[itemprop="
Offers "] [itemprop="
priceCurrency "]").getAttribute("content");
price.parentElement.setAttribute("style", "");
price.parentElement.innerHTML += '<h1 class="thePrice">' + price.innerText + " " + currency + '</h1>';
setTimeout(function() {
end();
}, 500);
}, 500);
}
This has been applied as a fix and the price returns now.
I am currently upgrading my livechat system to use the append function with JavaScript.
And in order to get it to work I will need to get the latest chat date or ID somehow.
So I can then do a query like:
SELECT date, message, name FROM chat WHERE id > $lastPostId";
This will then allow me to append all the latest messages instead of updating all of the HTML everytime there is a new message
So basically, my chat right now works like this:
Every second it checks for my PHP file, loadchat.php.
Loadchat.php will get every single message from the database
It then replaces all current data in my div: #chatbox by using .html() function.
And I want to change it to the append function in jquery allowing it to run a lot smoother
Because it only needs to read everything the first time and then append
So my question is, how do I get the last post ID?
Case 1:
Add one more field in your database called timestamp. When you update the chat you can store the value of last timestamp in session.Now each time fetching a new chat just send that timestamp to loadchat.php and query the db to fetch rows where timestamp > stored_timestamp.
Case 2:
You can take a flag in db like is_read. When you insert the new chat the default value of is_read will be 0. When you fetch the data just update the flag i.e is_read = 1. Now in your query you just have to check for the flag.
where is_read = 0.
It will fetch all the unread messages and will do the job.
Hope it will help!!
Im using AngularFire+Firebase and have data at firebase-database.
Im trying to paginate Data with Smart Table
My problem is that I dont know how to range query without specifying any child i,e fetch records from record # 25 to 35
Below query gives me first 5 records
var queryFIrst = visitRef.startAt().limitToFirst(5);
$scope.Visits = $firebaseArray(queryFIrst);
now Im trying to get records next 5,from 6 to 10 and I tried below
var queryFIrst = visitRef.startAt().limitToFirst(5).endAt().limitToFirst(5);
$scope.Visits = $firebaseArray(queryFIrst);
but it giving error that startAt and endAt can't be used like this with limit
In general pagination is not a good fit for Firebase's realtime data model/API. You're trying to model a SQL SKIP operator, which won't work with the Firebase Database.
But if you want to model pagination in Firebase, you should think of having an "anchor point".
When you've loaded the first page, the last item on that page becomes the anchor point. When you then want to load the next page, you create a query that starts at the anchor point and load n+1 item.
In pseudo-code (it's real JavaScript, I just didn't run it):
var page1 = visitRef.orderByKey().limitToFirst(5);
var anchorKey;
page1.on('child_added', function(snapshot) {
anchorKey = snapshot.key; // this will always be the last child_added we received
});
Now when you want to load the next page of items, you create a new query that starts at the anchor key:
var page2 = visitRef.orderByKey().startAt(anchorKey).limitToFirst(6);
A few things to note here:
You seem to be using an approach from the Firebase 1.x SDK, such as an empty startAt(). While that code may still work, my snippets use the syntax/idiom for the 3.x SDK.
For the second page you'll need to load one extra item, since the anchor item is loaded for both pages.
If you want to be able to paginate back, you'll also need the anchor key at the start of the page.
Is that what you needed that time?
visitRef.orderByKey().startAt("25").endAt("35")
I asked a similar question Get specific range of Firebase Database children