

JohnLM
Members-
Content Count
391 -
Joined
-
Last visited
Community Reputation
27 ExcellentTechnical Information
-
Delphi-Version
Delphi 11 Alexandria
Recent Profile Visitors
-
Copy a table from one database into another - [Solved]
JohnLM replied to JohnLM's topic in Databases
Progress update. . . Okay, I finally figured it out. SELECT * INTO TheNewTableName FROM '[g:\master.mdb].TheOldTableName WHERE 0=1; and then, INSERT INTO TheNewTablename SELECT * FROM ' + '[g:\master.mdb].TheOldTablename'; I created a new stand-alone test database(s) so that I would not damage the others. Anyway, it works and now I have to do a few changes and a few more test runs before I settle on this method. PS: To answer your questions. . . These two databases are mine. I have control. The first one, the main db (the source db) is a flat db, containing one table of about 14 fields. I only use two of those fields for daily updates throughout the day. This is a very small db of about 51MB in size and has been growing very slowly over the years, probably because some parts of the data are the same in many ways, I guess. -
I have two MS Access databases that I am reading through firedac in Delphi. I have an activity that I do every day: 1) I copy the source "data_Notes.mdb" and rename the copied version to "db.mdb". 2) Then I open the "db.mdb" in a delphi app for viewing certain info. 3) Then, when I'm finished, I delete the db file "db.mdb" and go through steps 1 through 3, thus rinse and repeat. However, I'd like to automate the process like this: (assuming I kept the "db.mdb" file in tact) 1) I delete the table "tblMyNotes" -- I already know how to do this in delphi code 2) copy the table "tblMyNotes" from the source db "data_MyNotes.mdb" -- I don't know how to do in delphi code 3) do whatever i want as usual with the table "tblMyNotes" 4) when I'm done, go through steps 1-3 again, re-copy it again, thus, rinse and repeat. The problem I am having is how to do the copying of the table from the source db to the "db.mdb" through delphi code. I am trying to find code that is as minimal and understandable as possible. So far, I have found this link, which seems to have what I am looking for, (a one-line SQL script to copy the table) but I can not understand fully what is going on, in order to get it to work, assuming this is one example of doing it. link: https://stackoverflow.com/questions/12242772/easiest-way-to-copy-a-table-from-one-database-to-another I have the following on my form: connection -> table -> ds-source I am testing various scenarios and have trying the following script, but it fails: Table.SQL.Add('CREATE TABLE tblTest SELECT * FROM "g:\data_notes.mdb".tblMyNotes'); Please advise your correction/suggestions, and TIA.
-
Date detection algorithm for strings
JohnLM replied to JohnLM's topic in Algorithms, Data Structures and Class Design
Update on this endeavor. . . I have three panes: 1. memo1 holds the source text 2. memo2 processes the output text, and 3. memo3 is the regex expression in multi-line format so i can better visualize what I am typing. (I use this to enter my expression for debugging) 3. to explain -- so instead of this one-line expression : (\d+[-\\.\/]\d+[-\\.\/]\d\d) we get this multi-line expression: \d+[-\\.\/] \d+[-\\.\/] \d\d) and the procedure StrContact() will restore the multi-line to a single line. Regarding how I am using regex. . . I am using the following routine(s) to process this memo's text: (I tried to remove anything not pertinant to this routine, as sometimes I leave junk in due to testing or debugging) function mytrim(str: string): string; // remove any spaces in string. var i : integer; begin for i := 1 to length(str) do begin if str[i] =' ' then delete(str,i,1); // remove the spaces from the expression if any end; result:=str; end; function strconcat(ts: tstrings): string; // concat the regex lines (pane 3) into one line of var // expressions for processing r: integer; begin for r := 0 to ts.Count-1 do begin result:=result+ts.Strings[r]; end; end; procedure TForm1.btnProcessClick(Sender: TObject); var r: integer; // index for the strings in the memo RegexText: string; // the filter guy match: TMatch; // show the regex matches matches: TMatchCollection; // process the items the match the regex (parameters) response: string; begin beep; m2.Lines.Clear; // memo2 ebRegex.Text := mytrim(strconcat(m3.Lines)); // memo3 - remove any ' ' spaces, -- multi-line expression to single line expression RegexText := ebRegex.text; // via TEdit -- the final expression to feed into regex for r := 0 to MemoResponse.Lines.Count-1 do begin // memo1 response := MemoResponse.Lines.Strings[r]; // memo1 -- regix processes each line, thus the reponse string to feed it. matches := TRegEx.Matches(response, RegexText); // memo1 for match in matches do begin if match.Success then m2.Lines.Add('Line: '+(r+1).ToString+' Match: '+match.Value); // memo2 end; end; end; And, now back to the issue I am having. The following does not work in my app using the above method: multi-line: /(^ \d+[-\/] \d+[-\/] \d\d\d\d)|( \d+[-\/] \d+[-\/] \d\d\d\d$) /gm into single-line: /(^\d+[-\/]\d+[-\/]\d\d\d\d)|(\d+[-\/]\d+[-\/]\d\d\d\d$)/gm I have noticed that some expressions do not work when I tweak around with the expression in the multi-line pane 3 area, though some parts may or may not work. But I can not figure out why, but they will work when plugged into the website. I have no solutions at this time. In time, I will figure these issues out. Thus, this is as far as I have gotten in this endeavor. -
Date detection algorithm for strings
JohnLM replied to JohnLM's topic in Algorithms, Data Structures and Class Design
I started looking at ways to use Regex in Delphi. I read that Regex started in XE. I am using XE7 (win-7). But I also have D12.2 (win-10) on my tablet which I haven't had the chance to test my app against since I would have to manually type the source into in order to test it. So my main testing and debugging regex under delphi is in XE7. However, I found an issue with getting regex to work in XE7 and was wondering, are there different implementation versions in Delphi? -
Date detection algorithm for strings
JohnLM replied to JohnLM's topic in Algorithms, Data Structures and Class Design
Progress. . . With a bit of time and effort from that website, so far I have the following success. I have not started anything in Delphi (using its support for RegEx), as that is another learning curve, but it will be interesting to see how I create something to help me identify dates and pull them. -
Date detection algorithm for strings
JohnLM replied to JohnLM's topic in Algorithms, Data Structures and Class Design
I googled and found out that Regex is included in Delphi, under System.RegularExpressions and RegularExpressionsCore. Time to do some more research into this area, and maybe try out the regex string that Anders posted earlier. -
Date detection algorithm for strings
JohnLM replied to JohnLM's topic in Algorithms, Data Structures and Class Design
I was not complete with that list. But for what its worth, I have other "odd" formats that I did not mention. Like 1.1.2020 and 1.1.20 and 01.01.20 and 010120mo, sept/2020 and 012020 and a few more. @Anders Melander - your regex suggestion looks interesting and promising. I have some learning to do. Thank you for your tip and the example. At first, I thought that I would have to do an overall cleanse of the file by discovering certain parts (patterns) and then breaking them up and redo the dates to a more standard format and then I would go through the list as a final stage and add the dates, if any, to the url output log in my app. Once that (the above idea) is complete, I am also considering changing the date to mm/yyyy or yyyy/mo format in the output log. -
Date detection algorithm for strings
JohnLM replied to JohnLM's topic in Algorithms, Data Structures and Class Design
@dummzeuch, you are correct, But thank you for your comment. -
Date detection algorithm for strings
JohnLM posted a topic in Algorithms, Data Structures and Class Design
I was wondering if there are algorithms for date detection inside strings. I have a text file full of hundreds of URL's and some of the url's have Dates and/or Times embeded, either on the left or right side of the url. These were entered by me over the years, since around 2014. I would copy and paste url's and sometimes write notes on the same line with the url. It didn't mean much to me at the time when I writting down the urls. Sometimes I was in a rush or under stress and just jotted them down the way I saw it in my head and fingers at the time. But now, the thought occurred to me that the dates could be important or be useful, today. As for the date, I did not make them standardised. Sometimes I would enter them as 1/1/2020, or 1.1.2020, or 1-1-2020, or 01012020. For instance. . . 1-1-2020 car sale http://www.cars.com 1/2/2020 car sale http://cars.com car sale http://cars.com 3/1/2020 Right now: 1. - I have an app that snipps just the url's, (any lines that have them) and then 2. - I remove the "www." portion for sorting and then removing duplicate urls 3. - now, I want to insert Dates if any. 4. - and finally, display a report output log - I will use the tmemo for this. Is there any custom function for date detection? Or else I will have to conjure up one myself. I don't mind doing one, but it may not be as efficient as expected. -
Working with AI for the first time
JohnLM replied to Alberto Paganini's topic in Tips / Blogs / Tutorials / Videos
Lately I've been asking "G" for some help and received some good answers. Things like, spelling, grammar and some Delphi questions. I did get some decent help on Delphi. But I just wish "G" would not keep my queries for their fiendish (diabolical) endeavors. If there were an offline aeye version I could download and run on my own, I would. Even better, if a download version and I create a small pop-up query, even bater! -
I knew there were faster versions. I had no doubt that members here can build something quick and far faster than my (snail's speed) version. My occurrences function took me over two weeks to reach this stage of success. I knew it was going to be very slow for large lists. I wrote it from scratch with no libraries and no guides, and no Google assist. I strictly wanted it to be educational and my own. I agonised over this the whole time. When I first started this endeavor, the first thing that popped into my mind was Pointers and bump values, but I lack the knowledge and understanding of them. I did try and study it at first, but it was too much for me to grasp and I wanted to do this as quickly as I could, so I withdrew the Pointer idea and went the non-advanced route. I was considering posting up the code here, from proof of concept and all, but thought I would get beaten up on the methods I used, among other things. Anyway. It works. Now all I need to do is fine-tune it, or make another attempt from scratch.
- 15 replies
-
- gettickcount64
- tstopwatch
-
(and 2 more)
Tagged with:
-
Here is the code snippet I used in this project. I copy/pasted into the first memo 39960 string values from an excel file. The 2nd memo holds the output of the number of occurrences and the completion times, as best I could get them working in this project. uses system.Diagnostics; . . var Form1: TForm1; starttime: tdatetime; finishtime: tdatetime; ElapsedTime, totaltime: tdatetime; sw: TStopwatch; swInfo: record swtime: string; hour : integer; min : integer; sec : integer; msec : integer; end; procedure TForm1.btn3Click(Sender: TObject); // this was a test button of several, so btn1, btn2, ... btn3, ... var Hour, Min, Sec, MSec: word; begin sw.Reset; sw := TStopwatch.StartNew; // Start measuring time // the number-of-occurrences processing code in-between these two sections. eT := GetTickCount64 - eT; m2.Lines.Add(eT.ToString + ' Msecs'); et:=et div 1000; m2.Lines.Add(eT.ToString + ' Msecs2'); ElapsedTime := Time - StartTime + Totaltime ; DecodeTime(elapsedtime, Hour, Min, Sec, MSec); m2.lines.Add(IntToStr(Hour) + ':'+ IntToStr(Min) + ':'+ IntToStr(Sec) + ':' + IntToStr(Msec)); m2.Lines.Add(FormatDateTime('hh:nn:ss:zzz',sw.ElapsedMilliseconds/MSecsPerDay)); end; ** m2 is a tmemo. I regularly use m1/tmemo1 and m2/temo2 a lot in my mini input/output reports. So it looks like it is taking 1.8 seconds to process this list of 39960 items.
- 15 replies
-
- gettickcount64
- tstopwatch
-
(and 2 more)
Tagged with:
-
Thanks @Kas Ob., I saw that post earlier today during my searches and trial/errors.
- 15 replies
-
- gettickcount64
- tstopwatch
-
(and 2 more)
Tagged with:
-
I could not figure out how to calculate the elapsed time for the values from GetTickCount64. I could only get the seconds by using (ET div 1000). I want at least seconds/msecs output. So I found some old code from one of my old projects that was using TStopWatch and that seems to be working acceptably well in this project. But once I figure out how to calculate what I need for gettickcount64, I will test both to see if they both report the same values or not, now that I am curious. I am running the values inside a tmemo along with the calculated number of occurrences list. I will post the code snippet in my follow-up post below, once I pull it out and incorporate it there for reference and/or critique. Fwiw, my programming skills are very limited.
- 15 replies
-
- gettickcount64
- tstopwatch
-
(and 2 more)
Tagged with:
-
I believe I have found the answer, but not the unit where it is located. It has be added like this: type TForm1 = class(TForm) btn1: TButton; m1: TMemo; procedure btn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; function GetTickCount64: uint64{QWord}; stdcall; external kernel32 name 'GetTickCount64'; // <--- added like this. var Form1: TForm1; ... I will test shortly.
- 15 replies
-
- gettickcount64
- tstopwatch
-
(and 2 more)
Tagged with: