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 default value of some field
SqlArray and default value of some field [message #33350] Wed, 27 July 2011 08:44 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

This post is connected with this one
http://www.ultimatepp.org/forum/index.php?t=msg&th=6105& amp; amp; amp;start=0&
and to the test case "SqlArray2.zip" provided by Sergey. I start a new topic as it is not specific of DropList and I am having problem even with OptionButton.

I have a SqlArray in which there are columns with DropList previuosly populated with some data. What I want is to let appear some default value in DropList. This default value should go in the database in case the user NOT modify its content.
In the Sergey test case the DropList is correctly populated:
		SQL * Select(SqlAll()).From(COUNTRY_T);
		while(SQL.Fetch()) {
			country.Add(SQL[0],SQL[1]);
		}

and then initialized to some default value
		
		country <<= "Russia";


When I insert a record the DropList seems lazy and does NOT show its supposed default and remains empty. If the user accept the row without to select an item the field remain empty.
I tried even
         country.SetIndex(1);

to wake up the lazy DropList but without success.
So I tried to modify the SCHEMA with the row
	INT_    (COUNTRY) SQLDEFAULT(12)

where '12' is the key code of value 'Russia'. Again the droplist remain empty and the database column too after accepting the row.
It seems the SQLDEFAULT does not work in sqlite3... if I have understood what it is intend for.

Any hint about setting a default value in SqlArray with embedded Ctrl?

Thanks,
Luigi

[Updated on: Wed, 27 July 2011 08:50]

Report message to a moderator

Re: SqlArray and default value of some field [message #33352 is a reply to message #33350] Wed, 27 July 2011 09:36 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Please upload testcase.

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: SqlArray and default value of some field [message #33353 is a reply to message #33352] Wed, 27 July 2011 10:02 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
sergeynikitin wrote on Wed, 27 July 2011 09:36

Please upload testcase.


Hello Sergey,

here it is (the same you send it to me).
Thanks,

Luigi
Re: SqlArray and default value of some field [message #33382 is a reply to message #33350] Sat, 30 July 2011 19:04 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
forlano wrote on Wed, 27 July 2011 02:44

Hello,

This post is connected with this one
http://www.ultimatepp.org/forum/index.php?t=msg&th=6105& amp; amp; amp; amp;start=0&
and to the test case "SqlArray2.zip" provided by Sergey. I start a new topic as it is not specific of DropList and I am having problem even with OptionButton.

I have a SqlArray in which there are columns with DropList previuosly populated with some data. What I want is to let appear some default value in DropList. This default value should go in the database in case the user NOT modify its content.
In the Sergey test case the DropList is correctly populated:
		SQL * Select(SqlAll()).From(COUNTRY_T);
		while(SQL.Fetch()) {
			country.Add(SQL[0],SQL[1]);
		}

and then initialized to some default value
		
		country <<= "Russia";


When I insert a record the DropList seems lazy and does NOT show its supposed default and remains empty. If the user accept the row without to select an item the field remain empty.
I tried even

Any hint about setting a default value in SqlArray with embedded Ctrl?



ArrayCtrl::IdInfo::InsertValue / ArrayCtrl::Column::InsertValue.

Mirek
Re: SqlArray and default value of some field [message #33385 is a reply to message #33382] Sat, 30 July 2011 22:19 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
mirek wrote on Sat, 30 July 2011 19:04

forlano wrote on Wed, 27 July 2011 02:44



Any hint about setting a default value in SqlArray with embedded Ctrl?



ArrayCtrl::IdInfo::InsertValue / ArrayCtrl::Column::InsertValue.

Mirek


Thank you,

the line

master.AddColumn(COUNTRY,"Country").SetConvert(Single<CountryConvert >()).Edit(country).InsertValue(12);

solved all the problems at once.
However i still wonder what SQLDEFAULT is intended to, or if I misused it. I believed it should take care of the default value.
Anyway one correct solution is enough Smile

Luigi
Re: SqlArray and default value of some field [message #33386 is a reply to message #33382] Sat, 30 July 2011 22:48 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Ñiao, Luigi.
Of course, what I suggest is not quite in the spirit of U + +. However, I do in my programs this way.

By the way the string
country <<= "Russia";
is not needed because it is an assignment before start editing the line of table.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Sat, 30 July 2011 22:49]

Report message to a moderator

Re: SqlArray and default value of some field [message #33388 is a reply to message #33385] Sun, 31 July 2011 09:03 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
forlano wrote on Sat, 30 July 2011 16:19

mirek wrote on Sat, 30 July 2011 19:04

forlano wrote on Wed, 27 July 2011 02:44



Any hint about setting a default value in SqlArray with embedded Ctrl?



ArrayCtrl::IdInfo::InsertValue / ArrayCtrl::Column::InsertValue.

Mirek


Thank you,

the line

master.AddColumn(COUNTRY,"Country").SetConvert(Single<CountryConvert >()).Edit(country).InsertValue(12);

solved all the problems at once.
However i still wonder what SQLDEFAULT is intended to, or if I misused it. I believed it should take care of the default value.
Anyway one correct solution is enough Smile



It does - on database schema level!

Inserting row into SqlArray is not the same thing as inserting it to DB.

If you would have issued statement

SQL * Insert

and omit the value for which you have defined SQLDEFAULT, database would fill it for you.

However, SqlArray in default mode does not even do SQL Insert befero you send the row into DB by hitting Enter. So it has to have a different set of default values, defined at SqlArray (/ArrayCtrl) level...

Mirek
Re: SqlArray and default value of some field [message #33391 is a reply to message #33388] Sun, 31 July 2011 14:40 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Thanks for this:
master.AddColumn(COUNTRY,"Country").SetConvert(Single<CountryConvert >()).Edit(country).InsertValue(12);



SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: SqlArray and default value of some field [message #33439 is a reply to message #33391] Fri, 05 August 2011 21:53 Go to previous message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
sergeynikitin wrote on Sun, 31 July 2011 14:40

Thanks for this:
master.AddColumn(COUNTRY,"Country").SetConvert(Single<CountryConvert >()).Edit(country).InsertValue(12);




Hello from Krakow Smile

Thanks all of you for the answers that I could read only today.
It is a pity I discovered SqlUpp (master detail) so late. I could have saved a lot of code. Now I am trying to rewrite it in a compact way.

Luigi
Previous Topic: [SQLITE] New version (3.7.0) introduces write-ahead logging.
Next Topic: sqlite and GridCtrl
Goto Forum:
  


Current Time: Fri Apr 26 00:51:50 CEST 2024

Total time taken to generate the page: 0.03510 seconds