From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.70.130.168 with SMTP id of8mr9832085pdb.9.1437679395911; Thu, 23 Jul 2015 12:23:15 -0700 (PDT) X-Received: by 10.140.33.199 with SMTP id j65mr224624qgj.31.1437679395863; Thu, 23 Jul 2015 12:23:15 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!pg9no3439203igb.0!news-out.google.com!4ni81876qgh.1!nntp.google.com!69no1529923qgl.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 23 Jul 2015 12:23:15 -0700 (PDT) In-Reply-To: <62c65777-8e64-4b70-a4dc-3138a4a29b2e@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.227.164.142; posting-account=HFCrOQoAAABZD_f-UUbYHm3lJDIrh-UX NNTP-Posting-Host: 85.227.164.142 References: <62c65777-8e64-4b70-a4dc-3138a4a29b2e@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0aaf871e-e4ba-41ed-9d1f-ca958dbada47@googlegroups.com> Subject: Re: Gnatcoll SQL questions From: joakimds@kth.se Injection-Date: Thu, 23 Jul 2015 19:23:15 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:27005 Date: 2015-07-23T12:23:15-07:00 List-Id: On Wednesday, July 8, 2015 at 10:21:02 PM UTC+2, NiGHTS wrote: > I am moderately experienced with the gnatcoll SQL library in that I have = used it with success and have studied some of its code and methods. Current= ly I am using it as an interface to SQLite but may use it in the future for= PostgreSQL. >=20 > Here are my questions. >=20 > 1. How do I delete data? I know this sounds simple but I can't delete any= data for the life of me. Here is an example of my code. >=20 > procedure proc > is > Query : GNATCOLL.SQL.SQL_Query; > =20 > begin > Query :=3D SQL_Delete (=20 > From =3D> data_db.Profiles, > Where =3D> data_db.Profiles.Id_Profiles =3D 1 > ); > =20 > Database_Connection.Execute ( Query ); > Database_Connection.Commit; > =20 > end proc; >=20 > Note that Database_Connection has been instantiated, initialized and has = a good connection to the database. I also know this because the program can= SELECT, UPDATE and INSERT just fine. But this particular DELETE function d= oes nothing at all to the database. I have also tried it omitting the entir= e "Where" line so it deletes all items in the Profiles table and yet no suc= cess. >=20 >=20 > 2. I would like to use GNATCOLL.SQL.Exec.Insert_And_Get_PK but I can't fi= gure out how to work with it. Previously I used Last_ID after my Insert's c= ommit but it always returned -1, so I figured it would be more effective to= use Insert_And_Get_PK instead. I can't find any examples anywhere (period)= so it would be great if I can get some pointers on how to use it. >=20 >=20 > In conclusion, why does the internet have so little documentation on Gnat= coll? I've read through the docs.adacode.com documentation on the SQL inter= face too many times to count but it is merely a basic overview. Does anyone= know of a good source of reference for Gnatcoll other than the source code= itself? Also helpful would be some kind of example source code, something = I can study from someone else's work. >=20 >=20 > Thank you in advance for your help. Dear mysterious NiGHTS, I just read your comment in another thread that you were disappointed that = you did not get feedbaack on this. Ada-Sweden has organized public meetups = on Ada and one of them was on GNATCOLL SQL: http://www.meetup.com/Ada-Stockholm/events/168383442/ You should have been there :-) Anyways, here is some feedback. When trying = out the GNATCOLL SQL I wrote a small application to keep track on peoples b= irthdays and store them in a PostgreSQL database. Here is the text-file describing the tables in the database: | TABLE | birthdays | birthday | | Contains the birthdays | | id | AUTOINCREMENT | PK | | Auto-generated ID | | age | INTEGER | | | | | name | TEXT | | | | Here is an excerpt from the source code for the code that created and delet= ed the birthdays in the database: procedure Create_Birthday(This : Database_API_Type; Birthday : out Model.Basic.Birthday_Type; Name : Model.Atomic.Birthday_Name_Type; Year : Model.Atomic.Birthday_Year_Type; Month : Model.Atomic.Birthday_Month_Type; Day : Model.Atomic.Birthday_Day_Type) is Query_Insert : constant GNATCOLL.SQL.SQL_Query :=3D GNATCOLL.SQL.SQL_Insert(Values =3D> (Database_Implementation.Auto_Generated_A= PI.Birthdays.Year =3D Integer(Year)) & (Database_Implementation.Auto_Generated_API= .Birthdays.Month =3D Integer(Month)) & (Database_Implementation.Auto_Generated_API= .Birthdays.Day =3D Integer(Day)) & (Database_Implementation.Auto_Generated_API= .Birthdays.Name =3D String(Name)) ); begin This.Connection.Reset_Connection; declare Primary_Key : constant Integer :=3D This.Connection.Insert_And_Get= _PK(Query =3D> Query_Insert, = PK =3D> Database_Implementation.Auto_Generated_API.Birthdays.Id); Birthday_Id : constant Model.Atomic.Birthday_Id_Type :=3D Model.At= omic.Birthday_Id_Type(Primary_Key); begin This.Connection.Commit_Or_Rollback; if not This.Connection.Success then raise Database.Atomic.Database_Error with This.Connection.Error= ; end if; Birthday.Initialize(Id =3D> Birthday_Id, Name =3D> Name, Year =3D> Year, Month =3D> Month, Day =3D> Day); end; end Create_Birthday; procedure Remove_Birthday(This : Database_API_Type; Id : in Model.Atomic.Birthday_Id_Type) is Query_Delete : constant GNATCOLL.SQL.SQL_Query :=3D GNATCOLL.SQL.SQL_Delete(From =3D> Database_Implementation.Auto_Gen= erated_API.Birthdays, Where =3D> Database_Implementation.Auto_Gen= erated_API.Birthdays.Id =3D Integer(Id)); begin This.Connection.Reset_Connection; This.Connection.Execute(Query =3D> Query_Delete); This.Connection.Commit_Or_Rollback; if not This.Connection.Success then raise Database.Atomic.Database_Error with This.Connection.Error; end if; end Remove_Birthday; The SQL query you have written for deleting a profile looks correct. Maybe = you need to reset the connection before executing the SQL query like done i= n the Ada code above? I think you've already solved these issues by now but the above feedback mi= ght be useful for someone else. Best regards, Joakim Strandberg