number signs in AdoTable.Filter - database

AdoTable1.Filter:=
'Date = #'+FormatDateTime('dd/mm/yyyy', Tomorrow)+ ' #' ;
Why is Date surrounded with number signs??
Is this Access -specific??
thanks in advance!

DrStrangeLove, the # sign (hash-marks) is the delimiter for a date field in access, you can check this paper for more info about delimiters in Access.
Access Basics for Programming: Delimiters

Related

How to convert or replace the string "-" to bracket "()" in vba

Dear All Master,
How to convert or replace the string "-" to bracket "()" in vba ?.
I can only do it manually with find and replace. The original record there were three thousand.
please recommend the solution.
FILENAME
DESIRED FILENAME
4715-(0).jpg
4715(0).jpg
TC45-1.jpg
TC45(1).jpg
TC51-1b.jpg
TC51(1b).jpg
TC52-B-1.jpg
TC52(B1).jpg
WSO.19-A.jpg
WSO.19(A).jpg
N.WAB25-AF.jpg
N.WAB25(AF).jpg
WA.4-K1.jpg
WA.4(K1).jpg
PD.133-AFa.jpg
PD.133(Afa).jpg
KP02-10.jpg
KP02(10).jpg
01-4-1-B.jpg
01-4-1(B).jpg
01-4-01-1.jpg
01-4-01(1).jpg
You could have a go with a regular expression. Something like:
-\(?(\w+)\)?(\.\w+)$
See an online demo
-\(? - Match an hyphen and an optional literal opening paranthesis;
(\w+) - A 1st capture group to match 1+ word-characters;
\)? - An optional closing paranthesis;
(\.\w+) - A 2nd capture group just to assert that previous matches are done before the extension. Here we match a dot and 1+ word-characters;
$ - End-line anchor to assert all previous matching is done at end of string.
You could chuck this into a VBA UDF and either call it from inside another sub or directly from th worksheet:
Public Function RegexReplace(s As String) As String
Static RE As Object: If RE Is Nothing Then Set RE = CreateObject("vbscript.regexp")
RE.Pattern = "-\(?(\w+)\)?(\.\w+)$"
RegexReplace = RE.Replace(s, "($1)$2")
End Function

Delphi FireDAC TFDQuery SQL Server DataTime filter problem

For the life of me, it seems I can't filter my TFDQuery using a DateTime field/format. I have this query that needs to "import" filters from a component (cxGrid), among them are:
"Date = " (DateTimeField);
"Value = " (FloatField);
"Supplier = " (StringField);
(And a few others, but those are the more important ones). Date is seconds sensitive, so it has HH:MM:SS, this is necessary for stock/contability purposes.
Now what I mean about "importing" filters is that I'm using the same filters as the ones current marked on a cxGrid. I do so using this simple method:
Filter := cxGridDBTableView.DataController.Filter.FilterText;
Which gives me a string of all the filters currently in use in that cxGrid.
I then toss this string in the filters of my query as in:
MyTFDQuery.Filtered := False;
MyTFDQuery.Filter := Filter;
MyTFDQuery.Filtered := True;
This posed a problem with Value, as we had a display format changing the float to a different format (from, let's say, 2.4 to 2,40) but this has already been fixed. Supplier and the other fields all worked like a charm, mostly because they didn't have a mask/display format.
My problem is when running the DateTime field (Date) filter, I get this error:
[FireDAC][Stan][Eval]-114. Expected []
This field has no display formats or masks of any kind.
I did try searching for this error code online, and couldn't find anything. I did try to change the format of the Date filter, seeing as many people had issues with the format. I have tried all forms of:
MyTFDQuery.Filter := 'Date = ''2021-01-01 10:00:00'''
MyTFDQuery.Filter := 'Date = {dt 2021-01-01 10:00:00}'
MyTFDQuery.Filter := 'Date = ' + Chr(39) + '2021-01-01 10:00:00' + Chr(39)
MyTFDQuery.Filter := 'Date = {CONVERT(''2021-01-01 10:00:00'', DATETIME)}
and many others that I can't recall from the top of my head, right now.
And also tried several different formats for the date... Such as:
YYYY-MM-DD
YYYY-DD-MM
DD-MM-YYYY
MM-DD-YYYY
Or even the separators for that date. I've tried ' - '; ' / '; ' . ' and the such (like 24.02.1982 instead of 24/02/1982). and kept on trying different ways to make this work, with different combinations.
When I searched about this issue online, specially in "how to filter a dataset/tfdquery by datetime", most people were being told to use different formats for the date/datetime to make it work. It seemed everyone had a different solution for this.
I'm not sure what to try anymore. Is this somehow connected to regional settings, as one search result pointed out? Where would those settings be from? The Delphi IDE? FireDAC? The DB I use? Is there something I'm missing?
Basically I want to know what format I should be using to filter my TFDQuery.
Thank you all for reading so far, any help would be highly appreciated. I hope the question is straightforward enough.
PS: I'm sorry for anything wrong I made have done in the making of this question. English is not my native language, and it's been a really long week. Thank you for the patience.
UPDATE: I've identified the error with a lot of guesswork. The milliseconds bit of the datetime is being taken into account when the filter is going to be applied to the dataset, and the cxGrid component would round the seconds (e.g changing '2021-02-01 18:05:03.822' to '2021-02-01 18:05:04').
That way, when the Date = '2021-02-01 18:05:04' would filter something, it wouldn't show up anything. It wasn't an issue with formatting, but rather with equality of datetimes.
To fix this, I followed Brian's advice and made the change:
cxGridDBTableView.DataController.Filter.DateTimeFormat := 'yy-mm-dd hh:mm:ss.zzz'
Now the millisecs are being taken from the filter, and the rounding ignored. Unfortunatelly I'm stuck on the error it gives:
[FireDAC][Stan][Eval]-118. Couldn't convert variant of type (UnicodeString) into type (Date)
Any further help would be highly appreciated.
I've found the "solution" to this problem. I simply assumed the query didn't accept the string filter with milliseconds, maybe some compatibility issues. I'm leaving this here in hopes that someone with a problem like mine can solve it fast, and maybe someone else can improve on this and make it more elegant/efficient.
I broke the string and inserted in a stringlist for easy management:
MyStringListFilters.LineBreak := ' AND ';
MyStringListFilters.Text := Filter;
This would turn a filter's string from:
((Date = ''28/09/2022 18:22:44.789'') OR (DATE = ''11/02/2019 07:18:03.122'')) AND ((Value = 2,4) OR (Value = 7,9)) AND (SUPPLIER = ''My Supplier Name Ltda'')
To:
((Date = ''28/09/2022 18:22:44.789'') OR (DATE = ''11/02/2019 07:18:03.122''))
((Value = 2,4) OR (Value = 7,9))
(SUPPLIER = ''My Supplier Name Inc'')
Now fixing the values is easy by just using a StringReplace:
While i < MyStringListFilters.Count do
if (Copy(MyStringListFilters[i], 2, 5) = 'Value') or (Copy(MyStringListFilters[i], 3, 5) = 'Value') then
StringReplace(MyStringListFilters[i], ',', '.', [rfReplaceAll]);
(When there is two or values, there will be an extra parentheses in front of the string).
Fixing the Date was a bit harder. I had to insert the string inside another string list, and break it up the same way:
//inside of the same while
if (Copy(MyStringListFilters[i], 2, 4) = 'Date') or (Copy(MyStringListFilters[i], 3, 4) = 'Date') then
begin
MyStringListDates.LineBreak := ' OR ';
MyStringListDates.Text := MyStringListFilters[i];
//it keeps on going...
Which further breaks the date string to:
((Date = ''28/09/2022 18:22:44.789'')
(Date = ''11/02/2019 07:18:03.122''))
Be aware: We have to remove the parentheses in the first filter and in the last as well if there is two or more Date filters. We also have to set things up as it was by the end of the loop. Do remember to always increment the index integer of both whiles.
//This happens inside the first while...
while j < MyStringListDates.Count do
begin
TempDate := Copy(MyStringListDates[j], 10, 19);
//This pulls the whole second, ignoring milliseconds from the DB.
MyStringListDates[j] := '((Date >= ' + QuotedStr(TempData) + ') and (Date < ' + QuotedStr(DateTimeToStr(IncSecond(StrToDateTime(TempData)))) + '))';
FixedDate := FixedDate + MyStringListDates[j];
if FixedDate = '' then
begin
// Puts the first parentheses back.
if MyStringListDates.Count > 1 then
FixedDate := '(';
FixedDate := FixedDate + MyStringListDates[j];
end
else
FixedDate := FixedDate + ' OR ' + MyStringListDates[j];
Inc(j);
end
//Remember to add the last parentheses here, if there is more than 1 Date Filter.
I would like to thank #Brian for their help with this solution. I didn't notice the component could be changed so the DateTime would come differently.
I would also like to thank #marc_s for editing the original question. This is my first question on the platform ever, so I didn't know what I was doing (Still don't. Sorry).
Also a special thanks to #Uwe Raabe, I've also used their answer on how to split strings using a multiple character delimiter on this problem. Here's the link to that question they answered:
How to split string by a multi-character delimiter?

Remove space between mobile number odoo 13

I want to remove space and '-' between the mobile number in odoo v13. Currently my mobile number format like this '+977 960-2582808'. From this format i want to remove space and '-'. This is mobile field in res.partner table with widget="phone".
expected result: +9779602582808
I am trying below code:
login_mobile = fields.Char()
mobile_sanitized = fields.Char(string='Mobile Number')
#api.onchange("login_mobile")
def onchange_device_id(self):
print('aaaaaaaaaaaaa')
self.mobile_sanitized = self.login_mobile.strip(' ')
Thanks in advance.
.strip() removes characters from beginning and end of the string.
EDIT
Use regular expression:
import re
self.mobile_sanitized = re.sub('[^0-9+]','', self.login_mobile)

VB.NET removing formatting from a formatted Phone number before inserting into SQL Server

I have a string when a telephone number is inputted - there is a mask so it always looks like (123) 456-7890 - I'd like to take the formatting out before saving it to the DB. I have it set up to only 10 charachters as nvarchar(10) - I only need it to be numbers like this 1234567890.
Another way to do it(basically replace every non number character with ""):
Imports System.Text.RegularExpressions //You need to Import this Namespace
Dim phone as string = "(123) 456-7890 -"
Dim match as string = Regex.Replace(phone, "[^\d]", "")
Console.WriteLine(match)
This outputs to: 1234567890
If you are using a MaskedTextBox then you could set the property TextMaskFormat
masked1.Mask = "(999)999-9999"
tb.Text = "(123)456-7890";
masked1.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals
....
Console.WriteLine(masked1.Text) ' => 1234567890
and when you get the Text property you get only the characters excluding the formatting characters
Notice that I have set the mask with 9 to allow only numbers. This of course depends on how telephone numbers are expected by your application.

Microsoft LogParser CSV output format - suppression of double quoting

I am having a problem with MS LogParser v2.2 and cannot seem to track down "the solution".
I am importing a UTF-16 TSV file with headers and am trying to export a subset of these fields this to a CSV file, generally with no processing, but with one instance of concatenating two of the fields with an intervening space (combining a first and last name into a full name).
The problem is that not only are all the fields double quoted irrespective of the oDQuotes argument (which I can happily ignore), but the concatenated field contains the result of that double quoting. I.e. given two fields Fred and Bloggs, the contents of the concatenated field is always
"Fred" "Bloggs"
rather than the less harmful
"Fred Bloggs"
or even
Fred Bloggs
no matter what the value of the oDQuotes parameter (OFF, AUTO or ON). The presence of these double quotes cannot be ignored or easily discarded.
I have tried this both in a batch file and in Windows Script:
e.g. Batch File:
set lp=%ProgramFiles(x86)%\Log Parser 2.2\LogParser.exe
set fields=[Buyer E-mail Address]
set fields=%fields%, [Order ID]
set fields=%fields%, [Shipping Addr 1]
set fields=%fields%, [Shipping Addr 2]
set fields=%fields%, [Shipping City]
set fields=%fields%, [Shipping Postal Code]
set fields=%fields%, [Buyer First Name]
::set fields=%fields%, strcat([Buyer First Name], ' ', [Buyer Last Name]) --- does not work. :-(
set fields=%fields%, strcat([Buyer First Name], strcat(' ', [Buyer Last Name]))
set fields=%fields%, [Buyer Last Name]
set fields=%fields%, [Buyer Company]
set fields=%fields%, [Buyer Day Phone]
set sql=SELECT %fields% into chad_out.csv from %1
"%lp%" -q:ON -i:TSV -icodepage:-1 -nSep:1 -fixedSep:on -o:CSV -oDQuotes:OFF -fileMode:1 "%sql%"
or JScript:
function ProcessFile(filename) {
DebugEcho(50, "D&D File name is <" + filename + ">");
var lq = WScript.CreateObject("MSUtil.LogQuery");
var lqif = WScript.CreateObject("MSUtil.LogQuery.TSVInputFormat");
var lqof = WScript.CreateObject("MSUtil.LogQuery.CSVOutputFormat");
// check that we actually have the objects in question
if (lq && lqif && lqof) {
DebugEcho(100, "Everything ok");
} else {
DebugEcho(0, "Something bad with LogQuery objects - exiting");
WScript.Quit(1);
}
// see command line "> LogParser.exe -h -i:TSV" for details
lqif.codepage = -1; // this is for unicode
lqif.fixedSep = true; // seems to need this
lqif.nSep = 1; // seems to need this?
// see command line "> LogParser.exe -h -o:CSV" for details
lqof.oDQuotes = "OFF"; // OFF | AUTO | ON - doesn't make any difference!
lqof.fileMode = 1; // 0 - append, 1 - overwrite, 2 - ignore
var fields = [
"[Buyer E-mail Address]",
"[Order ID]",
"[Shipping Addr 1]",
"[Shipping Addr 2]",
"[Shipping City]",
"[Shipping Postal Code]",
"[Buyer First Name]",
"strcat([Buyer First Name], strcat(' ', [Buyer Last Name]))", //
"[Buyer Last Name]",
"[Buyer Company]",
"[Buyer Day Phone]"
];
var sql = [
"SELECT",
fields.join(", "),
"INTO", "chad_out.csv",
"FROM", filename
].join(" ");
DebugEcho(20, "query string:", sql);
lq.ExecuteBatch(sql, lqif, lqof);
}
I'm afraid I can't actually give any data as it's confidential, but I hope that the illustration I have given is sufficient.
I do have other alternatives (i.e. Python csv) but this requires at least packaging the script into an executable (I do not wish to install Python as generally available software).
Can anyone spot something that I have obviously missed to control the behaviour of quoting or is this a deficiency of an otherwise powerful tool? Googling oDQuotes does not seem to be very productive.
It sounds like the quotes are in the input TSV file, aren't they? If that's the case, then the quotes are imported with the field values and you'll need to strip them off with your query (using SUBSTR(MyField, 1, -1)).
TSV does not expect quoted fields and thus it does not remove them.

Resources