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=-0.6 required=5.0 tests=BAYES_00, FILL_THIS_FORM_FRAUD_PHISH,FORGED_GMAIL_RCVD,FREEMAIL_FROM, T_FILL_THIS_FORM_SHORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b15952b348ae4fc3,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!2g2000hsn.googlegroups.com!not-for-mail From: azdakiel@gmail.com Newsgroups: comp.lang.ada Subject: Gnade/ODBC example - please help Date: Fri, 1 Aug 2008 05:18:38 -0700 (PDT) Organization: http://groups.google.com Message-ID: <4962abea-7622-45b3-a121-49286c636421@2g2000hsn.googlegroups.com> NNTP-Posting-Host: 83.24.3.212 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1217593118 5230 127.0.0.1 (1 Aug 2008 12:18:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 1 Aug 2008 12:18:38 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 2g2000hsn.googlegroups.com; posting-host=83.24.3.212; posting-account=svpIvgoAAAAV13MXsnedEjsNDyYD9m9H User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.51 (Windows NT 6.0; U; en),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:1407 Date: 2008-08-01T05:18:38-07:00 List-Id: Hi, I'm new here. I also just started my advanture with ADA. I'm building a portal using AWS (my project for university) and i need to connect to a MySQL database. I using Gnade/ODBC interface. There is simple example, in the Gnade User's Guide, how to connect and get some data from databese. And it works. And now my problem: This example shows how to pass integer parameter to the query and get string and float from the database. I trying to pass to the query string and the boolean (...WHERE NAME = name AND IsVisible = visible...) and I can't. I have no idea how to rewrite this example. Is there anyone who can tell me how to change this example? ---------------=========The Example========------------ with Ada.Characters.Handling; with Ada.Command_Line; with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Ada.Text_IO; use Ada.Text_IO; with Ada.Exceptions; use Ada.Exceptions; with GNU.DB.SQLCLI; use GNU.DB.SQLCLI; with GNU.DB.SQLCLI.Bind; with GNU.DB.SQLCLI.Info; use GNU.DB.SQLCLI.Info; with GNU.DB.SQLCLI.Info.Debug; with GNU.DB.SQLCLI.Environment_Attribute; use GNU.DB.SQLCLI.Environment_Attribute; with GNU.DB.SQLCLI.Environment_Attribute.Debug; with GNU.DB.SQLCLI.Connection_Attribute; use GNU.DB.SQLCLI.Connection_Attribute; with GNU.DB.SQLCLI.Connection_Attribute.Debug; use GNU.DB.SQLCLI; with GNAT.Traceback.Symbolic; procedure odbc_mysql is package RIO is new Ada.Text_IO.Float_IO (SQLDOUBLE); EnvironmentHandle : SQLHENV; ConnectionHandle : SQLHDBC; ServerName : constant String := String'("test"); UserName : constant String := String'("test"); Authentication : constant String := String'("test"); Quoting_Character : Character := Character'Val (34); function QuoteIdentifier (ID : String) return String; procedure Get_Identifier_Info; function QuoteIdentifier (ID : String) return String is begin return Quoting_Character & ID & Quoting_Character; end QuoteIdentifier; pragma Inline (QuoteIdentifier); procedure Get_Identifier_Info is QC : constant Driver_Info_String := Driver_Info_String (SQLGetInfo (ConnectionHandle, SQL_IDENTIFIER_QUOTE_CHAR)); begin if QC.Value'Length /= 1 then null; else Quoting_Character := QC.Value (QC.Value'First); end if; end Get_Identifier_Info; begin SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, EnvironmentHandle); SQLSetEnvAttr (EnvironmentHandle, Environment_Attribute_ODBC_Version' (Attribute => SQL_ATTR_ODBC_VERSION, Value => SQL_OV_ODBC3)); SQLAllocHandle (SQL_HANDLE_DBC, EnvironmentHandle, ConnectionHandle); SQLConnect (ConnectionHandle => ConnectionHandle, ServerName => ServerName, UserName => UserName, Authentication => Authentication); Get_Identifier_Info; declare package Double_Binding is new GNU.DB.SQLCLI.FloatBinding (SQLDOUBLE); package DB renames Double_Binding; type ManagerID is new SQLINTEGER; type ManagerID_Ptr is access all ManagerID; package ManagerID_Binding is new GNU.DB.SQLCLI.Bind (ManagerID, ManagerID_Ptr); package MB renames ManagerID_Binding; StatementHandle : SQLHSTMT; Search_Manager : aliased ManagerID := 2; Len : aliased SQLINTEGER := 0; Name : aliased String := 20 * '.'; Firstname : aliased String := 20 * '.'; Len_Firstname : aliased SQLINTEGER; Len_Name : aliased SQLINTEGER; Len_Salary : aliased SQLINTEGER; Salary : aliased SQLDOUBLE; begin SQLAllocHandle (SQL_HANDLE_STMT, ConnectionHandle, StatementHandle); SQLPrepare (StatementHandle, "SELECT " & QuoteIdentifier ("NAME") & ", " & QuoteIdentifier ("FIRSTNAME") & ", " & QuoteIdentifier ("SALARY") & " FROM " & QuoteIdentifier ("EMPLOYEES") & " " & "WHERE " & QuoteIdentifier ("MANAGER") & " = ? " & "ORDER BY " & QuoteIdentifier ("NAME") & "," & QuoteIdentifier ("FIRSTNAME")); MB.SQLBindParameter (StatementHandle => StatementHandle, ParameterNumber => 1, InputOutputType => SQL_PARAM_INPUT, ValueType => SQL_C_SLONG, ParameterType => SQL_INTEGER, ColumnSize => 0, DecimalDigits => 0, Value => Search_Manager'Access, BufferLength => 0, StrLen_Or_IndPtr => Len'Access); SQLBindCol (StatementHandle, 1, Name'Access, Len_Name'Access); SQLBindCol (StatementHandle, 2, Firstname'Access, Len_Firstname'Access); DB.SQLBindCol (StatementHandle, 3, Salary'Access, Len_Salary'Access); SQLExecute (StatementHandle); begin loop SQLFetch (StatementHandle); SQLFixNTS (Name, Len_Name); SQLFixNTS (Firstname, Len_Firstname); Put (Name); Put (", "); Put (Firstname); Put (", "); RIO.Put (Item => Salary, Fore => 5, Aft => 2, Exp => 0); New_Line; end loop; exception when No_Data => null; end; end; SQLCommit (ConnectionHandle); SQLDisconnect (ConnectionHandle); SQLFreeHandle (SQL_HANDLE_DBC, ConnectionHandle); SQLFreeHandle (SQL_HANDLE_ENV, EnvironmentHandle); end odbc_mysql; ====================================================== Thanks, Hubert Walter