Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » SqlArray and data validation
SqlArray and data validation [message #33343] Tue, 26 July 2011 20:51 Go to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

I have a SqlArray with several EditString in the columns and the user can add record at his pleasure but I do not want to pollute the database of records with almost empty fields (with space for example).
So the question is: How is the recommended way to validate the data the user enters BEFORE they are gone in the databas

Thanks,
Luigi
Re: SqlArray and data validation [message #33355 is a reply to message #33343] Wed, 27 July 2011 12:48 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
forlano wrote on Tue, 26 July 2011 20:51


So the question is: How is the recommended way to validate the data the user enters BEFORE they are gone in the databas



I suspect the solution is WhenPreQuery callback...

EDIT: No, it isn't...

[Updated on: Wed, 27 July 2011 13:14]

Report message to a moderator

Re: SqlArray and data validation [message #33358 is a reply to message #33343] Wed, 27 July 2011 17:37 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
Hello, Luigi.

forlano wrote on Tue, 26 July 2011 20:51


How is the recommended way to validate the data the user enters BEFORE they are gone in the database


I suggest to use Accept function to check if valid values used for Ctrls (more about this here, on 18 section).
To set valid values SetFilter or SetConvert (with creation of specialised Convert class) functions may be used.
Also, NotNull property of Ctrl can be used to prevent empty values. TrimLeft, TrimRight or TrimBoth EditString Ctrl functions to trim spaces from left, right or both sides, respectively.

In the case of ArrayCtrl/SqlArray you could try to use WhenAcceptRow, WhenAcceptEdit notification callbacks in conjunction with IsEdit, IsInsert ArrayCtrl functions.

[Updated on: Wed, 27 July 2011 18:48]

Report message to a moderator

Re: SqlArray and data validation [message #33360 is a reply to message #33358] Wed, 27 July 2011 19:51 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Sender Ghost wrote on Wed, 27 July 2011 17:37

Hello, Luigi.

forlano wrote on Tue, 26 July 2011 20:51


How is the recommended way to validate the data the user enters BEFORE they are gone in the database


I suggest to use Accept function to check if valid values used for Ctrls (more about this here, on 18 section).
To set valid values SetFilter or SetConvert (with creation of specialised Convert class) functions may be used.
Also, NotNull property of Ctrl can be used to prevent empty values. TrimLeft, TrimRight or TrimBoth EditString Ctrl functions to trim spaces from left, right or both sides, respectively.

In the case of ArrayCtrl/SqlArray you could try to use WhenAcceptRow, WhenAcceptEdit notification callbacks in conjunction with IsEdit, IsInsert ArrayCtrl functions.


Hello,

thanks for the suggestions. I'll try them.

Luigi
Re: SqlArray and data validation [message #33362 is a reply to message #33360] Thu, 28 July 2011 00:16 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
In your case (with spaces and empty values) you might use following example:
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class App : public TopWindow {
public:
	typedef App CLASSNAME;
	App();
	// Ctrls
	EditString text; // or EditStringNotNull
	ArrayCtrl list;
	// Events
	bool OnAcceptRow();
};

App::App()
{
	Title("Data validation example");
	CenterScreen().Sizeable().MinimizeBox().MaximizeBox();
	SetRect(Size(320, 240));

	Add(list.SizePos());

	text.NotNull().TrimBoth(true);

	list.Appending();
	list.AddColumn("Text").Edit(text);
	list.WhenAcceptRow = THISBACK(OnAcceptRow);
}

bool App::OnAcceptRow()
{
	const String& data = text.GetData();

	if (data.IsEmpty())
		return false;

	return true;
}

GUI_APP_MAIN
{
	Ctrl::GlobalBackPaint();

	App app;
	app.Run();
}
Re: SqlArray and data validation [message #33363 is a reply to message #33362] Thu, 28 July 2011 08:48 Go to previous message
forlano is currently offline  forlano
Messages: 1182
Registered: March 2006
Location: Italy
Senior Contributor
Sender Ghost wrote on Thu, 28 July 2011 00:16

In your case (with spaces and empty values) you might use following example:



Thank you, I needed just that!
Everything is clear now.

Luigi
Previous Topic: master/detail sqlite3 example
Next Topic: Timestamp accuracy in postgres and upp
Goto Forum:
  


Current Time: Thu Mar 28 16:36:38 CET 2024

Total time taken to generate the page: 0.01718 seconds