Re: [sqlite] Field not editable
sorry, it works well with a trigger and raise(abort, ‘cause'). Le 13 févr. 2014 à 09:50, O.D. vidal a écrit : > > Hello all, > > I would like a field is not editable. What is the best solution? > > For example, I have a table Country: > > id - Name > > 1 - Brazil > 2 - Canada > ... > > I want the name of the country can not be changed. > > Thank you! > Greetings > > olivier > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Field not editable
ok, thank you very much Simon! olivier Le 13 févr. 2014 à 11:01, Simon Slavin a écrit : > > On 13 Feb 2014, at 9:55am, O.D. vidal wrote: > >> Why do you say: >> >>> This would normally be done inside your programming language. >> >> strengthen the rule directly in the database seems common sense. > > I can see that argument, which is why I bothered figuring out the TRIGGER. > > However, anyone who is able to make changes to the data in that database can > also make changes to the TRIGGERs in the database. So they could just DROP > that TRIGGER. They would be less likely to be able to change the software > that is being used to edit the data. > > Your question is an example of a long term discussion about whether your > entire business philosophy should be encoded within your SQL databases, with > numerous FOREIGN KEYs, CONSTRAINTs and TRIGGERs used to enforce how you run > the business. The two sides of the argument are about evenly matched and > there are no conclusions yet. > > I hope you manage to implement a solution which suits you. > > Simon. > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Field not editable
Thank you Simon! Why do you say: > This would normally be done inside your programming language. strengthen the rule directly in the database seems common sense. olivier Le 13 févr. 2014 à 10:37, Simon Slavin a écrit : > > On 13 Feb 2014, at 8:50am, O.D. vidal wrote: > >> I would like a field is not editable. What is the best sol >> ution? >> >> For example, I have a table Country: >> >> id - Name >> >> 1 - Brazil >> 2 - Canada >> ... >> >> I want the name of the country can not be changed. > > This would normally be done inside your programming language. However it > might be possible to enforce the rule inside SQLite using a TRIGGER: > > <http://www.sqlite.org/lang_createtrigger.html> > > It might looks something like > > CREATE a TRIGGER > UPDATE ON Country > WHEN new.name != old.name > BEGIN > RAISE (FAIL, 'Not allowed to change the name of a country.') > END > > Note: I just made that up off the top of my head and have no idea whether it > will work. > > You will have to guard against > > (A) people DROPping the TRIGGER, and > (B) people deleting the row from the Country table and making a new one with > a different name. > > Simon. > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Field not editable
Hello all, I would like a field is not editable. What is the best solution? For example, I have a table Country: id - Name 1 - Brazil 2 - Canada ... I want the name of the country can not be changed. Thank you! Greetings olivier ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users