101

(13 replies, posted in General)

Hi Alaa,
.
From my experience, it's not possible to UPDATE existing data from a simple CSV import.  It will only add to the existing data like you observe.  I usually clear the table prior to importing.
.
I think it would require some scripting for it to prevent duplication, but sorry I haven't done this before.

Hey Derek,
.
I was afraid that was an open, subjective question there.  But your response has given me some confidence in what I have going so far.  The project I have is working fine, but noticed those last two (unaddressed) items you mentioned.  This may have started my second guessing.
.
Thanks a lot for giving those different examples too!
.
Going back to this secondary project example, I added the month/year filter similar to the one from my other post.  I cannot get the dateTimePicker to start auto-checked in this project.
.
I have set and unset both checked and default checked properties, but this doesn't seem to do anything.  So, I tried writing it in a script to check it.  When I do this, the box is checked, but the tablegrid isn't filtered. (it is followed with searchButton.click too)
.
Not sure what's causing this, because it's working fine in my other main project so this is kinda minor...
.
But it leads to another (more important) request I have: while the dateTime filter is checked, when a new record is created, it removes the filter and shows all the records (even though it is still checked).
.
How can I keep the filter in place and prevent this from happening?  You can observe it with this project.

Greetings derek and sparrow,
.
Thank you both for these quick responses, and especially for the added explanations!
.
I believe I was heading in the direction that sparrow provided, but as he put it: derek has a much nicer solution for this problem.


I'm going back to the drawing board on this design because I'm having trouble deciding which fields should be stored and which only need to be calculated...
.
My thinking is that since these values are reset annually- they don't need be stored, but this is where I'm confused.  Should this be a deciding factor?
.
I guess the values could be (just as easily) reset at the beginning of each year.
.
How would you more experienced folks handle this? wink

I am leading up to the subject of this topic, but I ran into another issue along the way...
.
I feel like someone has pointed this out to me before, but I skimmed my posted topics and none of them revealed anything.  So, it may have been in another thread.  Forgive me for asking this again (in that case), but I couldn't find it.
.
So a brief description of this project:  I'm tracking attendance records for employees.  I left out the details from my last posted topic, but I have those in place already.
.
The issue I'm currently having is getting the calculated field cfVacEarned to return the same values I get from the SQL query in my external browser.  I have included the screenshot which is what I'm expecting to see in MVD.  It appears that MVD is using the same value from the first record for all the other records.  What's the best way to fix this?
.
I could use some help with this part to get to my next question lol
.
I also wanted to point out this project as well because it has given me additional ideas for the one I'm working on.

Great!
.
Thanks to each of you for being patient and making suggestions.  I'm still learning how to create a decent database.  This portion of my project is complete, and it's working good now.
.
Yeah derek, I know those things are purely preference and sometimes habit.  I had been wondering all this time, so thanks for sharing.  I have experimented with the grid size some, and I do like the grid size on a smaller number than the default now.
.
Many many thanks!

Okay, so I made some minor changes to get the results I had in mind:
.
So since the date is always required, I hide the checkbox for that field.  I created a "dummy" hidden time field to always store the time.  And I wanted to make use of the checkbox (for the user interface) on the visible time field because it is optional.
.
This is what I came up with, and it seems to be working okay.  But I would appreciate any feedback from anyone that will have a look at it.


Again derek, I appreciate that example with the tableGrid conditions and testing.  Very helpful for me.  I haven't done any of that yet.


I have some arbitrary questions (for anyone that has posted in this thread) about some of your settings (in the IDE I guess).  When some of you offer solutions:
.
1. I notice the tabstops or spacing is set to two.  The default in MVD is like four, so I'm just curious if you folks use a different editor for the scripts?  Because I see no way to change this in MVD.  (Unless you don't use the tab key lol )
.
2. Also (particularly with derek) the Grid size seems to be different.  Mine is set to eight which is the installation default.  I notice because without manually changing position values, my controls don't ever line up with the ones from your projects.
.
These are kinda random questions, but I have always been curious.

Hi derek,
.
I appreciate your response (and the extra explaination), as always!
.
I didn't mean to take away your cfmonth, I was more curious if it could be done (and if there were any differences).  I would probably need to carry it across to FastReport, so thanks for using that technique.
.
Yes- at first, I was presetting the time.  Then I got the idea to show and use the checkbox for the time field.  That was working good until I wanted to remove the display of seconds and AM/PM.  So I noticed after reformatting the tableGrid it started showing the 00:00.  I do like the way the default simply doesn't show if it's 00:00, but I'm guessing that's also a result of whether or not the checkbox is checked.  Haven't tested that.
.
For this project, there is only ever a 12-14 hour window, and so a time of 00:00 falls outside of it.  So it worked out that the default tableGrid was hiding that hour.  My apologies for not mentioning that detail, and thanks for considering it.
.
So testing values in the tablegrid is new to me, so I wasn't even sure how to make that happen.  I might have more questions once I look it over more closely, but for now- Thank you.

Hi folks,
.
Welcome back derek, and thanks for chiming in on this.  No, I haven't moved on as I'm still weighing out the different options and how to approach it.


brian
Thanks for your last suggestions.  I was able to get it working in a different project, so I'm pretty sure it's a timing issue with when the format is being applied in the project with the error.
.
I do have another question now though... but let me add an extra detail to this:
.
There will always be a date, but the time is optional.  I noticed in the default tableGrid formatting of the DateTime field that when the time is midnight 00:00:00, it doesn't even display the time (and I prefer this).  However, when that grid format is applied, the time 00:00 is always displayed.  Is there a way to ignore the time when it's midnight like in the default?
.
In my attached example, I am using a button instead of the OnChange event to demonstrate my question above.


derek
I have a few questions about your project, if you will.
.
1. Also in my attached example, I used your approach without the event.cfmonth but instead event.eDate.  Do you see where this could cause a problem?  Is the cfmonth necessary?
.
2. In your example, you use copy(frmmain.dtpfilter.sqldate,2,7).  I was trying to figure out why you start with 2.  I tested 0 and 1, and in both cases it included the first double quote ".  Are 0 and 1 returning the same thing in this case?  Would you explain this further, please?
.
Also thanks for the suggestion for leaving the checkbox on the filter date.  I hadn't thought about that.


general questions
1.
It's not necessary to deal with seconds or mseconds with the time field.  On the frmDetail when I use format HH:mm, it indeed hides the seconds and the AM/PM, but it's still recording the seconds and possibly the mseconds.  I need those to always be 00 in any case.  That way- if there is a way to do the formatting described above, the time will be hidden in the tableGrid.
.
2.
Because the time is optional, on the frmDetail the dtpTime is linked to the dtpDate, so when the Time is unchecked the date is also not saved.  I have some ideas on how keep the time excluded (maybe by using other hidden controls and scripts).  Is there a better way of doing this?
.
This is the issue I was having in my last post where I was talking about using two separate fields again.  I don't particularly like this idea.  So I'm still experimenting for now.


[edit] forgot to add the project tongue [/edit]

Hi brian, thanks for that example too.
.
I know this is spinning off into another direction now (from the original post).  I wasn't sure whether to create a new topic, so I'm continuing here for now.  It's related to date and time, and specifically towards your last example...
.
So after getting further into my project, I decided that it might be better to separate the two fields.  eDate and eTime instead of using a single eDateTime field like I originally decided to do.  I'll get into that a bit later.
.
I was using your column format example above, but I'm getting an error.  Instead of formatting money though, I'm formatting time.  I don't see why that would be an issue though- maybe it is?
.
The frmMain_OnShow event includes:

TNxNumberColumn(frmMain.TableGrid1.Columns[2]).FormatMask := 'H:mm';

.
And that works fine, until the grid changes (loosing the format), but when I place that line inside the frmMain_TableGrid1_OnChange event it halts the program and says:
.
List index out of bounds (2)
.
There are only 3 columns: Name [0], Date [1] and Time [2]
.
When I change it to Columns[1] it's applying it to the date column (which is expected).  I haven't tested the code in your example, but I'm sure it works.  So the only other thing I can think of is that you're calling a custom procedure, but it's doing the same thing.  Might be in a different order though...  Any thoughts?
.
[edit]
Just because I was curious I tried two other ideas:
.
1. using TNxTimeColumn instead of TNxNumberColumn
2. calling from a custom procedure like in your example
.
Still the same error complaining about an invalid column index
[/edit]

brian,
.
Thank you for the explanations.  I will try to learn a bit more about triggers now, because it sounds like they would be useful in the next step of this project.  This is where my knowledge with SQL ends.  I have heard about triggers, but I've never used them before... so the journey beings.
.
Thanks also for the tip about saving them outside of MVD.  I'm sure this will be very useful once I learn more about them.
.
As far as the calculated fields, I'm sure it depends on the situation (as always).  But I was just curious if you had some determining factors that made you go one way or the other on when to use them.
.
sparrow,
.
I can't explain how helpful it is for me to finally get this formatting issue resolved in FastReport- I was beginning to think it wasn't possible.  I appreciate the comparison between the two ways of doing this in your example too.  I'm beginning to understand this a bit more now, and I really appreciate both of your contributions!
.
Regarding your last post, I don't follow where that would go.  The TNxNumberColumn makes me think of a report...  But then again, the complete line seems like the syntax inside a script procedure call... I can't decide for sure tho.
.
Thanks once again guys!

111

(6 replies, posted in Script)

Yes, in the words of Dmitry:

Please attach your project.

wink

Thanks again to both of you for contributing your hints and techniques here!
.
It's a little too late to mention this now, but for this project it wasn't necessary for the AM/PM part.  But you both have thoroughly covered that in detail, and I will use it for the future- I'm sure.


brian,
.

I rarely use calculated fields on the applications I am working on. I rather use trigger or save-it-in-database.

.
I am curious about this...  Will you elaborate on cases when you would and would not use calculated fields?  (just in general)
.
Also in your example, you saved-it-in-database, but I'm not sure that I am familiar with what you meant by "use trigger".  Will you describe what this is too, please?
.
And thanks for pointing out that 0.99999 detail, because I started using this technique in some of my other projects now wink
.
No worries about the reporting, I will adjust it too.  Who prints anything these days, right? lol


sparrow,
.
Your code snippet for the red field text in FastReport is precisely what I was looking for, Thank you!  But this also leads me to believe (and answers my very last question about the DisplayFormat property in FastReport) that it doesn't work. Perhaps this is the proper way to accomplish this with MVD and its included version of FastReport.
.
Going back to your other suggestion:
.

2. in format tab select Date\Time and "format string" type mmmm (or what do yo want... for example hh:mm am/pm   )
the same as
  DisplayFormat
    FormatStr: mmmm
    Kind: fkDateTime

.
[edit]
Excuse me, I follow what you were saying now... you have to make that call in the report prior to changing those properties AND THEN it will display that format...
[/edit]
.
Your last CASE WHEN example is much cleaner than the one I was using.  The modulus operator didn’t come to mind, nor did searching for a generic solution to that.  I get tunnel vision sometimes, so I just resorted to using that similar structure for the SQL line to convert the month numbers into words.


Many many thanks guys, I’m still learning the MVD ways, and this has helped a bunch!

So progressing a little further... At first, I liked sparrow's simple two lines, but I have implemented brian's solution because it was easier to do reports without using Report (SQL).
.
I have a few other questions now for anyone:
.
1) The tableGrid shows the time formatted (in 12-hour format) which is how I would like to extract it.  I know this doesn't apply, but the C++ reference to strftime has a %I.  That's what I'm looking for here.
.
I have three different sites I reference for the SQLite strftime function, but they only show %H for the 24-hour portion.  Also, most all the related posts here that I've skimmed mainly deal with the date portion.
.
So, my cfTime is using: strftime('%H:%M',event.eDateTime) for now.
.
I'm working on a conversion.  So, I created a cfHour to convert it, but I'm wondering if there is a better way to do this?  I need to report the time also.
.
2) I have a cfMonthName field primarily for the reports.  Because I can never get FastReport to DisplayFormat to work.  I tried this on the eDateTime field (the red date on the report):
.
Report
  DisplayFormat
    FormatStr: mmmm
    Kind: fkDateTime
.
But it only shows the full date.  I'm guessing this is not an option?  So, the cfMonthName is necessary in this case.

114

(4 replies, posted in General)

Yeah I didn't mean to complicate your question, so probably best to disregard my post.
.
I started out with two name fields in a project I was working on.  Then I needed to add an optional name and so this was how I handled it.  There is probably an even better way to do it, but I wanted to share what I came up with for that.  You know... in case you might add a 3rd name sometime.  lol

Thank you brian, and sparrow.
.
This turns out to be more involved than I expected (with scripts).  But I am glad that it's not as simple as changing properties in the controls, because I feel like I tried many different combinations with all of them at some point.
.
I have learned something from both.
.
But again, I appreciate you both for taking time to answer.

Greetings,
.
I searched and found similar posts to this, but they are using older versions...  I'm trying to filter records containing a DateTime field by the Month and Year only.  Showing all days and times within the selected month and year.
.
I have gotten this to work using two separate Date and Time fields, but it doesn't seem to work the same with a single DateTime field unless I use the >= Filter.  But, I would rather it be for a specific month and year instead.
.
In the other test project using a Date and Time field, the time would always be 00:00:00 in the date field and the date would always be 1899-12 in the time field.  So, I thought that it's probably better to use a single field instead.
.
I've attached an experiment project.  Is this possible, what am I doing wrong?

117

(4 replies, posted in General)

Heya,
.
I know this doesn't apply to you for this case in your project, but I was solving a similar combination of names just recently.  I wanted to share what I came up with for a semi-logical concatenation snippet:
.

ifnull(nullif(employee.nameLast || ', ' || employee.nameFirst || ' (' || employee.nameNick || ')', employee.nameLast || ', ' || employee.nameFirst), employee.nameLast || ', ' || employee.nameFirst)

.
I needed an if this else that type of logic in a calculated field.  As far as I know, there is no such structure for calculated fields.  I was about to ask for help with it, but then I experimented with the ifnull and nullif combinations and got it working as desired.
.
Anyways, maybe it will help someone else in the future.

118

(2 replies, posted in SQL queries)

I knew it was a simple answer.  I just couldn't find it (didn't know what to search for, or where to look).
.
Still learning the datatypes.  I stumbled across the SQLDateTimeToDateTime() today.  It may have also worked, but I haven't tested it.
.
I know about the f(x) reference in MVD.  When I choose the Types category, everything begins with T and I get overwhelmed there.  I guess I need to start referring to the delphi page now because I just noticed that type is listed there (more clearly for me).
.
Many thanks sir!

119

(5 replies, posted in Reports)

Wow sparrow, thanks for pointing out those details.  I had not looked into it far enough to determine that.  I didn't intend for you to make a comparison with the two hmm
.
I appreciate all your help even though I don't follow everything in your last post.  Your previous solutions seem to have fixed the problems that I was having, but I'm bookmarking this if I notice something else down the road.

120

(2 replies, posted in SQL queries)

Hello folks,
.
I felt like this is a silly elementary question, but I cannot figure out how to convert the types that a SQLExecute returns.  It obviously works as a string, but for anything else:

var dateHire : date;

dateHire := strToDate(SQLExecute('SELECT dateHire FROM employee where ID = ' + frmEmpRecord.tbEmpID.Text));

or

dateHire := strToDateTime(SQLExecute('SELECT dateHire FROM employee where ID = ' + frmEmpRecord.tbEmpID.Text));

.
I get "not a valid date and time"
.
and
.

dateHire := SQLExecute('SELECT dateHire FROM employee where ID = ' + frmEmpRecord.tbEmpID.Text);

.
I get "could not convert variant of type (UnicodeString) into type (Double)"
.
so then I try:
.

var dateHire : double;

dateHire := StrToFloat(SQLExecute('SELECT dateHire FROM employee where ID = ' + frmEmpRecord.tbEmpID.Text));

.
I get "not a valid floating point value"
.
so then I try removing the StrToFloat and get the (Unicode String) error again...
.
I sifted through several pages of forum posts for related examples.  I'm not sure what else to try.  Would someone be kind enough to help me out here?  I have had this issue in the past, but I usually found another way around it.  But I wanted to reach out and find the proper way of doing this for future use...

121

(12 replies, posted in General)

I must say that this is awesome brian!  Thank you for sharing this example big_smile

122

(5 replies, posted in Reports)

Hi sparrow,
.
Thank you for reviewing this issue and I appreciate your patience answer this question (again).  It seems that it's coming from the same error in the beginning: with the null values which are missing from the table during input.
.
It is very much appreciated!  This makes sense, and I will pay more attention to this in future projects now.
.
As for your second post, I answered another user here (perhaps too late) that was asking how to do that very thing.  At the time, I wasn't sure... but now I am running into the same problem.  LOL  Apparently they were able to identify this at an earlier stage than myself.
.
Hats off to you.

123

(5 replies, posted in Reports)

Hello MVD fans,
.
I pulled this from an older project, but I added a sample report to demonstrate the issue that I've been trying to solve recently.  IMHO this project has a pretty solid database structure and schema with enough sample data to show my problem (again).
.
I'm also calling the standard report from MVD without using SQL, but I still have the same issue described from one of my other topics: [SOLVED] Report Grouping Totals with NULL Values
.
Everything works prefectly except for (this time integer) values being treated as strings (which I believe is) causing this concatination behavior.  It was the Real values in my other post.  I can't seem to pin down what I'm doing wrong to make this happen?
.
<see the screenshot>
.
I would appreciate any help or ideas.

Here lately, I have been experimenting with FastReport a bit further (trying to identify the original problem I was having).  I am convinced that it is a datatype issue.
.
I believe that the data is being stored improperly (maybe somewhere in my code), and not necessarily with the SQL sent to FastReport.  In another quick ad-hoc project, it calculates the real values correctly using SUM().  So this far, I have gotten two different results with real values:

  1. SUM() produces a concatination of the real values (it does this with strings).

  2. SUM() produces a total of the real values (as expected).

In both cases, the datatypes are Real in both MVD and SQlite, and the `DisplayFormat` property in FastReport has no effect either.
.
I made sure (to my best ability) that the datatypes are correct in the code.  Even though MVD will not allow improper datatypes to be stored within the software, but I'm not sure how to verify it in SQLite.  FastReport seems to be treating the real values as strings with concat or something.
.
In this screenshot:

  • The left group - (these values have been clipped) but the integers in the left column are being calculated correctly with SUM(), but the real values in the right column are being concatinated.

  • The right group - the real values also being calculated correctly from the ad-hoc project.

.
This project is a bit large to just scrap and start over, so I'm trying to troubleshoot the problem at this point.
.
Although the IFNULL solution provided by sparrow seems to be working, I would rather identify the problem causing this concatination behavior in my first example if possible...

sonixax,
.
Without seeing your project and from my interpretation of your request, I would suggest experimenting with a `record_count` field to keep track of the items in your database.  I had forgotten about this until recently, and it has solved many issues for me.
.
I'm not sure if I can provide a solution for your request, but adding a sample of what you're working with will certainly get a faster response.  Just my two cents.