~ubuntu-branches/ubuntu/feisty/fpc/feisty

« back to all changes in this revision

Viewing changes to fcl/db/odbc/testsql.pp

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-01-27 20:08:50 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070127200850-9mrptaqqjsx9nwa7
Tags: 2.0.4-5
* Fixed Build-Depends.
* Add myself to Uploaders in debian/control.
* Make sure that the sources are really patched before building them.
* Build unit 'libc' on powerpc too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
program testsql;
2
 
{$mode objfpc}
3
 
uses fpodbc,Classes,odbcsql;
4
 
 
5
 
var
6
 
  Conn : TODBCConnection;
7
 
  St : TODBCSQLStatement;
8
 
  FieldNames : TStringList;
9
 
  I,Count : Integer;
10
 
 
11
 
procedure DumpFielddef(F : TODBCField);
12
 
 
13
 
begin
14
 
  Writeln('Field ',F.Position,' : ',F.Name);
15
 
  Writeln('Type : ',F.DataType);
16
 
  Writeln('Size : ',F.Size);
17
 
  Writeln('Decimal digits : ',F.DecimalDigits);
18
 
  Writeln('Nullable : ',F.Nullable);
19
 
end;
20
 
 
21
 
procedure DumpField(F : TODBCField);
22
 
 
23
 
begin
24
 
  With F do
25
 
    begin
26
 
    Write(Name:12,BufType:5,'  ');
27
 
    If IsNull then
28
 
      Writeln('(Null)')
29
 
    else
30
 
      Case BufType of
31
 
        SQL_Smallint : Writeln(AsInteger);
32
 
        SQL_Integer  : Writeln(AsInteger);
33
 
        SQL_BIT      : Writeln(AsInteger);
34
 
        SQL_CHAR     : Writeln(AsString);
35
 
        SQL_DOUBLE   : Writeln(AsDouble);
36
 
        SQL_DATE,
37
 
        SQL_TIME,
38
 
        SQL_TIMESTAMP,
39
 
        SQL_TYPE_DATE,
40
 
        SQL_TYPE_TIMESTAMP,
41
 
        SQL_TYPE_TIME : Writeln(AsString);
42
 
      else
43
 
        Writeln('Unknown field type');
44
 
      end;
45
 
    end;
46
 
end;
47
 
 
48
 
 
49
 
begin
50
 
  Conn:=TODBCConnection.Create(Nil);
51
 
  Try
52
 
    Conn.DSN:='FPC';
53
 
    Conn.Active:=True;
54
 
    ST:=TODBCSQLStatement.Create(Conn);
55
 
    Try
56
 
      ST.SQL.Text:='Select * from fpdev order by id';
57
 
      Writeln('Opening');
58
 
      ST.Open;
59
 
      Writeln('Opened');
60
 
      Try
61
 
        FieldNames:=TStringList.Create;
62
 
        Try
63
 
        st.GetFieldList(FieldNames);
64
 
        Writeln('Found ',FieldNames.Count,' Fields in result set :');
65
 
        For I:=0 to FieldNames.Count-1 do
66
 
          Writeln(i+1,': ',FieldNames[i]);
67
 
        Writeln('End of list');
68
 
        Writeln('FieldDefs:');
69
 
        with st.fields do
70
 
          for I:=0 to COunt-1 do
71
 
            DumpFielddef(st.fields.items[i] as TODBCField);
72
 
        Writeln('Data dump:');
73
 
        Count:=0;
74
 
        While not st.eof do
75
 
          begin
76
 
          Inc(Count);
77
 
          Writeln('Record no ',Count,' : ');
78
 
          Writeln('Name':12,'Type':5,'  Value');
79
 
          for I:=0 to st.fields.COunt-1 do
80
 
            DumpField(st.fields.items[i] as TODBCField);
81
 
          st.fetch;
82
 
          end;
83
 
        Writeln('End of data');
84
 
        finally
85
 
          FieldNames.Free;
86
 
          Writeln('Freed list');
87
 
        end;
88
 
      Finally
89
 
        st.Close;
90
 
        Writeln('Closed');
91
 
      end;
92
 
    Finally
93
 
      ST.Free;
94
 
      Writeln('Freed statement');
95
 
    end;
96
 
    Conn.Active:=False;
97
 
    Writeln('Disactivated connection');
98
 
  Finally
99
 
    Conn.free;
100
 
    Writeln('Freed Connection');
101
 
  end;
102
 
end.