EnglishРусский  

   ..

   ged.g

   gedbase.g

   geddemo.g

Реклама

Инсталлятор CreateInstall
Бесплатные и коммерческие инсталляторы

source\lib\ged\geddemo.g
  1 #exe = 1
  2 #output = k:\gentee\open source\gentee\exe\geddemo.exe
  3 /******************************************************************************
  4 *
  5 * Copyright (C) 2009, The Gentee Group. All rights reserved. 
  6 * This file is part of the Gentee open source project - http://www.gentee.com. 
  7 * 
  8 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT"). 
  9 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS 
 10 * ACCEPTANCE OF THE AGREEMENT.
 11 *
 12 * Author: Alexey Krivonogov ( gentee )
 13 *
 14 ******************************************************************************/
 15 
 16 include : "ged.g"
 17 
 18 define
 19 {
 20    PATH = $"c:\temp"
 21    DBNAME = "\$PATH\\demo.ged"
 22 }
 23 
 24 func uint ged_notify( ged pdb )
 25 {
 26    str stemp
 27    
 28    if pdb.filename : stemp.copy( pdb.filename )
 29    print("Notify \( pdb.error )\n")
 30    switch pdb.error
 31    {
 32       case $GDE_GEDEXIST
 33       {
 34          return 0 // Overwrite existing database
 35 //         return !conyesno("Database \( pdb.dbfile ) exists. Overwrite? (Y/N)" )
 36       }
 37       case $GDE_OPENFILE : print( "ERROR: Cannot open file \( stemp )\n")  
 38       case $GDE_WRITEFILE : print( "ERROR: Cannot write file \( stemp )\n")  
 39       case $GDE_FORMAT : print( "ERROR: Wrong GED format of \( stemp )\n")  
 40       case $GDE_READFILE : print( "ERROR: Cannot read file \( stemp )\n")  
 41    }
 42    return pdb.error
 43 }
 44 
 45 method ged.printrec()
 46 {
 47    str out
 48    uint i
 49    out = "\( ?( this.isdel(), "*", " " ))\( this.reccur )"
 50    fornum i, this.fieldcount()
 51    {
 52       str stemp
 53       this.getstr( i, stemp )
 54       out += " >\(stemp)"
 55    }
 56    out += "\l"
 57    print( out )
 58 }
 59 
 60 method gedsel.printrec()
 61 {
 62    str out
 63    uint i recno
 64    recno = ged_goto( this.pdb->ged, ges_recno( this ))
 65    out = "\( this.reccur ) N\( recno )"
 66    fornum i, this.pdb->ged.fieldcount()
 67    {
 68       str stemp
 69       this.pdb->ged.getstr( i, stemp )
 70       out += " >\(stemp)"
 71    }
 72    out += "\l"
 73    print( out )
 74 }
 75 
 76 func main<main>
 77 {
 78    ged        pdb
 79    collection cfield
 80    uint       i
 81    arrstr     in
 82    str        path
 83    
 84    cfield = %{ $FT_INT | $FTF_AUTO, "id" ,
 85                $FT_SHORT, "short",
 86                $FT_BYTE, "char", 
 87                $FT_LONG, "long", 
 88                $FT_DOUBLE, "real",
 89                $FT_FLOAT, "float",
 90                $FT_STR | ( 16 << 16 ), "email",
 91                $FT_USTR | ( 16 << 16 ), "name" }
 92                
 93    pdb.create( $DBNAME, cfield, &ged_notify );
 94    pdb.open( $DBNAME, &ged_notify );
 95    print( "Field index: email = \( pdb.findfield( "email" 
 96                    )) qqq = \( pdb.findfield( "qqq" ))\n" )
 97    fornum i = 0, pdb.fieldcount()
 98    {
 99       uint fi
100       
101       fi as pdb.field( i )
102       print( "\(i + 1): type=\( fi.ftype ) \("".copy( fi.name )) width = \(
103                fi.width ) off = \( fi.offset )\n" )
104    }
105    pdb.append();
106    pdb.append( %{ 0, 1, 2, 30123456789L, 2.123, 4.13F, "test@....com", "John Smith" });
107    print( "Number of records = \( *pdb )\n" )
108    
109    foreach curdb, pdb : pdb.printrec()
110    pdb.close()
111    
112    path.fgetdir( $_FILE )
113    ffind fd
114    
115    fd.init( path.faddname("*.g"), $FIND_FILE )
116    foreach cur,fd
117    {
118       str stemp
119       
120       stemp.read( cur.fullname )
121       in.load( stemp, $ASTR_APPEND | $ASTR_TRIM )  
122    }
123    
124    pdb.open( $DBNAME, &ged_notify );
125    fornum i = 0, 100
126    {
127       pdb.append( %{ 0, i, i & 0xf, 0L, 0.0, 0F, in[i*2], in[i*2+1] });
128    }     
129    foreach curdb, pdb : pdb.printrec()
130    print("=====================================\l")
131    
132    gedsel sel
133        
134 /*   sel.open( pdb, %{ $SF_EQ | $SF_OR, "id", 56,
135                      $SF_GREAT | $SF_OR, "id", 90,
136                      $SF_EQ, "email", "{" }, %{10} )*/
137    sel.open( pdb, %{ $SF_GREAT | $SF_NOT, "name", "fi" }, 
138                   %{ "char", $IF_DESC, "email", 0 } )
139    print( "Number of records = \( *sel )\n" )
140    pdb.append( %{ 0, 1, 255, 301L, 0.123, 4.13F, "film@....com", "film" });
141    sel.update()
142 //   sel.reverse()
143    foreach cursel, sel : sel.printrec()
144    print("======================================\l")
145    sel.close()
146    pdb.close()
147    congetch( "Press any key..." )
148 }
Редактировать