Select in ADO (vb6) with a numeric variable - vb6

Excuse me, occasionally I refer with some problem that maybe it's already been fixed. In any case, I would appreciate a clarification on vs.
I have a TariffeEstere table with the fields country, Min, Max, tariff
from which to extract the rate for the country concerned, depending on whether the value is between a minimum and a maximum and I should return a single record from which to extract its tariff:
The query is:
stsql = "Select * from QPagEstContanti Where country = ' Spain '
and min <= ImpAss and max >= ImpAss"
Where ImpAss is a variable of type double.
When I do
rstariffa.open ststql,.....
the recodset contains a record if e.g. ImpAss = 160 (i.e. an integer without decimals), and then the query works, but if it contains 21,77 ImpAss (Italian format) does not work anymore and gives me a syntax error.
To verify the contents of the query string (stsql) in fact I find:
Select * from QPagEstContanti Where country = 'Spain' and min < = 21,77 and max > = 21,77
in practice the bothering and would like a comma decimal, but do not know how do.
I tried to pass even a
format (ImpAss, "####0.00"),
but the value you found in a stsql is 21,77 always.
How can I fix the problem??

It sounds like the underlying language setting in SQL is expecting '.' decimals instead of ',' decimal notation.
To check this out - run the DBCC useroptions command and see what the 'language' value is set to. If the language is set to English or another '.' decimal notation - it explains why your SQL string is failing with values of double.
If that's the problem, the simplest way to fix it is to insert the following line after your stsql = statement:
  stsql = REPLACE(stsql, ",", ".")
Another way to fix it would be to change the DEFAULT_LANGUAGE for the login using the ALTER LOGIN command (but this changes the setting permanently)
Another way to fix it would be to add this command to the beginning of your stsql, which should change the language for the duration of the rs.Open:
  "SET LANGUAGE Italian;"

Related

How can I use 'update where' select in FoxPro?

I am totally new to FoxPro (and quite fluent with MySQL).
I am trying to execute this query in FoxPro:
update expertcorr_memoinv.dbf set 'Memo' = (select 'Memo' from expertcorr_memoinv.dbf WHERE Keymemo='10045223') WHERE Keydoc like "UBOA"
I got the error:
function name is missing )
How can I fix it?
In FoxPro SQL statements you would not 'single-quote' column names. In Visual FoxPro version 9 the following sequence would run without errors:
CREATE TABLE expertcorr_memoinv (keydoc Char(20), keymemo M, Memo M)
Update expertcorr_memoinv.dbf set Memo = (select Memo from expertcorr_memoinv.dbf WHERE Keymemo='10045223') WHERE Keydoc like "UBOA"
If you would provide a few sample data and an expected result, we could see whether the line you posted would do what you want after correcting the single-quoted 'Memo' names.
NB 1: "Memo" is a reserved word in FoxPro.
NB 2: As you know, the ";" semicolon is a line-continuation in Visual FoxPro, so that a longer SQL statement can be full; of; those;
So that the Update one-liner could be written as:
Update expertcorr_memoinv ;
Set Memo = (Select Memo From expertcorr_memoinv ;
WHERE Keymemo='10045223') ;
WHERE Keydoc Like "UBOA"
NB 3: Alternatively, you can SQL Update .... From... in Visual FoxPro, similar to the Microsoft SQL Server feature. See How do I UPDATE from a SELECT in SQL Server?
I would do that just as Stefan showed.
In VFP, you also have a chance to use non-SQL statements which make it easier to express yourself. From your code it feels like KeyMemo is a unique field:
* Get the Memo value into an array
* where KeyMemo = '10045223'
* or use that as a variable also
local lcKey
lcKey = '10045223'
Select Memo From expertcorr_memoinv ;
WHERE Keymemo=m.lcKey ;
into array laMemo
* Update with that value
Update expertcorr_memoinv ;
Set Memo = laMemo[1] ;
WHERE Keydoc Like "UBOA"
This is only for divide & conquer strategy that one may find easier to follow. Other than that writing it with a single SQL is just fine.
PS: In VFP you don't use backticks at all.
Single quotes, double quotes and opening closing square brackets are not used as identifiers but all those three are used for string literals.
'This is a string literal'
"This is a string literal"
[This is a string literal]
"My name is John O'hara"
'We need 3.5" disk'
[Put 3.5" disk into John's computer]
There are subtle differences between them, which I think is an advanced topic and that you may never need to know.
Also [] is used for array indexer.
Any one of them could also be used for things like table name, alias name, file name ... (name expression) - still they are string literals, parentheses make it a name expression. ie:
select * from ('MyTable') ...
copy to ("c:\my folder\my file.txt") type delimited

Change value psql where value between, as string

I have a query that must set a value if the number is between 2 values, but the output is not ok, I think because that column is a string. Any way to do it even it's string?
(In output I have value as , 5 witch is not ok).
All the values that are incorrect are Integer.
SET lkp_age_category_id = 7
WHERE
age BETWEEN '26' and '35.99';
I guess, only working on the SQL side, you could cast the values right into the query, e.g.:
SET lkp_age_category_id = 7
WHERE age BETWEEN '26'::float AND '35.99'::float;
Also check this answer https://stackoverflow.com/a/13809603/917617.

string.IndexOf exact match

I have the following:
string text = "Select [id] AS [FROMId] FROM [TASK] ORDER BY id"
and I want to use text.IndexOf("FROM") in order to find where the FROM starts.
I want to find the position of FROM and not the position of FROMId.
LastIndexOf or FirstIndexOf are not correct answers cause the text could be anything like
string text = #"Select [id] AS [FROMId],
newId as [newFROMId] FROM [TASK] ORDER BY [FROMId]"
I need the indexof to do exact matching.
Any ideas?
Since FROM is an SQL reserved word that will generally have spaces on either side, you could look for that then, since that will give you the address of the space before the F, add one to get the location of the F itself:
int index = text.IndexOf(" FROM ") + 1
This may not necessarily take care of all edge cases(a) but, to do that properly, you may have to implement an SQL parser to ensure you can correctly locate the real from keyword and distinguish it from other possibilities.
(a) Such as things like:
select [a]FROM[tble] ...
select 'got data from unit #' | unit from tbl ...
and so on.

How to solve invalid parameter error using Codeigniter and Pesapal

Am trying to test my payment module using codeigniter and pesapal but I keep getting this error "Problem: parameter_rejected | Advice: invalid_value_for_amount> oauth_parameters_rejected | Ksh.4%2C999".
Where Ksh. 4%2C999 is the bill ksh. 4999. I have used the right Pesapal keys so I don't know what am doing wrong.
Problem
Your amount has a thousand separator ... something like this Ksh.4,999 instead of passing a value that's an integer like 4999.
Either you are passing in the amount with the comma (which you can fix by removing the comma in your logic) or the number_format() method is adding the thousand separator (explanation given below in solution).
Solution
According to the PHP docs number_format() does something like this (basic case only)...
// english notation (default)
$english_format_number = number_format($number);
// 1,235
Note how it's added a , as the thousand separator. This is what is being converted(encoded) to %2C. Pesapal doesn't understand numbers with the , which is what you are passing to them. ... to stop the function from using the thousands operator do something like this ...
// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
3rd parameter specifies the decimal separator (which is .) and the 4th specifies the thousand separator (which is an empty string).
But as #BabyAzerty has said, without code there's nothing much that we can work with to assist you. I'll amend the answer the more context you give to your problem but the above is pretty much what I've seen wrong with your implementation elaborated in the question and comment above.
$amount1 = (integer)$data->amount;
$amount = number_format($amount1, 2, '.', '');//format amount to 2 decimal places
$desc = $data->phone_type;
$type = "MERCHANT"; //default value = MERCHANT
$reference = $data->reference;//unique order id of the transaction, generated by merchant
$first_name = $data->name1;
$last_name = $data->name2;
$email = $data->email;
$phonenumber = $data->mobile;//ONE of email or phonenumber is required
This error means that your account on Pesapal has a limit on the amount it can transact. By default the amount is usually set to USD 10 or the equivalent of it in local currency.
You need to contact the team at support.pesapal.com to complete your sign-up by submitting contract and documents for your business in order to have the account activate for full transactions.

Whats the XPath equivalent to SQL In query?

I would like to know whats the XPath equivalent to SQL In query. Basically in sql i can do this:
select * from tbl1 where Id in (1,2,3,4)
so i want something similar in XPath/Xsl:
i.e.
//*[#id= IN('51417','1121','111')]
Please advice
(In XPath 2,) the = operator always works like in.
I.e. you can use
//*[#id = ('51417','1121','111')]
A solution is to write out the options as separate conditions:
//*[(#id = '51417') or (#id = '1121') or (#id = '111')]
Another, slightly less verbose solution that looks a bit like a hack, though, would be to use the contains function:
//*[contains('-51417-1121-111-', concat('-', #id, '-'))]
Literally, this means you're checking whether the value of the id attribute (preceeded and succeeded by a delimiter character) is a substring of -51417-1121-111-. Note that I am using a hyphen (-) as a delimiter of the allowable values; you can replace that with any character that will not appear in the id attribute.

Resources