From: Andrey C. <sku...@us...> - 2006-10-20 10:30:52
|
Update of /cvsroot/eas-dev/eas/libcodb_query In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv1276 Modified Files: codb.prg command.prg formatter.prg Makefile Log Message: Support comments, expand * for SELECT fields, DROP statement, quit codb by ESC Index: codb.prg =================================================================== RCS file: /cvsroot/eas-dev/eas/libcodb_query/codb.prg,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- codb.prg 2 Jun 2006 14:32:45 -0000 1.1 +++ codb.prg 20 Oct 2006 10:30:23 -0000 1.2 @@ -1,9 +1,9 @@ /*-------------------------------------------------------------------------*/ -/* This is part of console client for CODB database */ -/* */ -/* Copyright (C) 2005 by E/AS Software Foundation */ -/* Author: Andrey Cherepanov <sk...@ea...> */ -/* */ +/* This is part of console client for CODB database */ +/* */ +/* Copyright (C) 2005 by E/AS Software Foundation */ +/* Author: Andrey Cherepanov <sk...@ea...> */ +/* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as */ /* published by the Free Software Foundation; either version 2 of the */ @@ -11,6 +11,7 @@ /*-------------------------------------------------------------------------*/ #define FILE_BUFFER 4096 +#include "inkey.ch" static clientVersion := "0.1" static db, dbname:="", fmt @@ -20,6 +21,7 @@ - connection string for connect via COBrA server (-u, -p, -s) - exit function for correct connection shutdown - 'set <param>=<mode>' command needed + - CODB daemon for query mode */ /* Main function */ @@ -137,18 +139,19 @@ /* Console mode. Using readline library */ static function consoleMode() - local comm:='', ret, prompt, buffer:='', cont:=.F., oErr + local comm:='', ret:='', prompt, buffer:='', cont:=.F., oErr // TODO: set key '\d' for exit prompt := dbname + "> " oErr := ErrorBlock({|e| break(e) }) while .T. - begin sequence + begin sequence ?? prompt - ACCEPT TO comm // TODO: Ctrl-C handle! + ACCEPT TO comm // TODO: Ctrl+C safe handle! + //?? "KEY:",chr(10) if .not. cont - if alltrim(upper(comm)) == 'QUIT' + if alltrim(upper(comm)) == 'QUIT' .or. lastkey() == K_ESC exit elseif upper(comm) == 'HELP' ret := codb_execute( db, comm+";" ) @@ -160,19 +163,19 @@ ret := executeCommand(buffer+comm) - if empty(ret) + if empty(ret) .or. substr(ltrim(ret),1,1) == '#' prompt := dbname + "> " cont := .F. buffer := '' else // Uncomplete command - prompt += iif(dbname!='',replicate('-',len(dbname)),'-') + "> " + prompt := iif(.not. empty(dbname),replicate('-',len(dbname)),'-') + "> " cont := .T. buffer := ret + ' ' endif - recover using oErr + recover using oErr ?? "INTERNAL ERROR:", oErr:description+' ('+oErr:fileName+')', chr(10) - end sequence + end sequence enddo return Index: command.prg =================================================================== RCS file: /cvsroot/eas-dev/eas/libcodb_query/command.prg,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- command.prg 20 Jun 2006 10:25:52 -0000 1.4 +++ command.prg 20 Oct 2006 10:30:23 -0000 1.5 @@ -1,9 +1,9 @@ /*-------------------------------------------------------------------------*/ -/* This is part of console client for CODB database */ -/* */ -/* Copyright (C) 2005 by E/AS Software Foundation */ -/* Author: Andrey Cherepanov <sk...@ea...> */ -/* */ +/* This is part of console client for CODB database */ +/* */ +/* Copyright (C) 2005 by E/AS Software Foundation */ +/* Author: Andrey Cherepanov <sk...@ea...> */ +/* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as */ /* published by the Free Software Foundation; either version 2 of the */ @@ -17,9 +17,6 @@ - WHERE in SELECT statement: translate logical operation and quotes - export/import - use file content as command list - - CODB daemon for query mode - - DROP statement - - comment support - SET DBF CHARSET TO <> */ @@ -29,6 +26,7 @@ { "create", @ec_create(), "Create metaobject" }, ; { "delete", @ec_delete(), "Delete object or metaobject" }, ; { "describe", @ec_describe(), "Show metaclass structure" }, ; + { "drop", @ec_drop(), "Delete metaobject by its name" }, ; { "get", @ec_get(), "Get object from repository" }, ; { "metaget", @ec_metaget(), "Get metaobject" }, ; { "metaput", @ec_metaput(), "Create or update metaobject" }, ; @@ -236,7 +234,7 @@ /* Execute database command */ function codb_execute( self, cmd, db, files ) - local oErr, a:=array(0), r, i, key, ret, is_string:=.F., p, part:= '' + local oErr, a:=array(0), r, i, key, ret, is_string:=.F., is_comment:=.F., p, part:= '', pos // Create result object r := CODB_Result() @@ -280,13 +278,21 @@ loop endif + // Process comments + if cmd[i] == '#' + is_comment := .T. + endif + if cmd[i] == "&\n" .and. is_comment + is_comment := .F. + endif + if cmd[i] $ " &\t&\n," if i>1 .and. .not. cmd[i-1] $ " &\t&\n," aadd( a, part ) part := '' endif pos := i+1 - else + elseif .not. is_comment part := part + cmd[i] endif next @@ -497,7 +503,7 @@ /* 'SHOW' command */ static function ec_show( self, cmd, res, files ) - local oErr, dbh, dbl, i, j, pos, d:=self:dict, o, class + local oErr, dbh, dbl, i, j, pos, d:=self:dict, o, class, c_db if len(cmd) == 1 return "Metaclass name is missed" @@ -626,7 +632,7 @@ /* Get raw object*/ static function ec_get_object( self, id, res, files, d ) - local oErr, cEnt + local oErr, cEnt, dbl if valtype(d) == 'O' cEnt := 'metaobject' @@ -665,7 +671,7 @@ /* Put raw object*/ static function ec_put_object( self, obj, res, files, d, class ) - local oErr, id + local oErr, id, cEnt if valtype(d) == 'O' cEnt := 'metaobject' @@ -710,7 +716,8 @@ /* 'GET' command */ static function ec_get( self, cmd, res, files, d ) - local oErr, aKeys, k, p, v, class:="", attr, cEnt, oClass, j, oAttr + local oErr, k, p, v, class:="", attr, cEnt, oClass, j, oAttr, dbl + local aKeys, aNames, i if valtype(d) == 'O' cEnt := 'metaobject' @@ -1016,7 +1023,7 @@ /* 'DELETE' command */ static function ec_delete( self, cmd, res, files ) - local oErr, d:=self:dep, aKeys, k, p, v + local oErr, d:=self:dep, aKeys, k, p, v, dbl if len(cmd) == 1 return "Id is missed" @@ -1045,6 +1052,55 @@ end sequence return NIL +/* 'DROP' command */ +static function ec_drop( self, cmd, res, files ) + local dbl, oErr, d:=self:dict, j, class, id + + if len(cmd) == 1 + return "Metaobject class is missed" + endif + + if len(cmd) < 3 + return "Name is missed" + endif + + if empty(d) + return "Select database first ('use <DBNAME>')" + endif + + oErr := ErrorBlock({|e| break(e) }) + + //?? "delete",cmd[2],cmd[3],chr(10) + begin sequence + // Lookup metaobject + j := ascan(aMClassesDesc, {|e| e[1]==lower(cmd[2]) }) + if j == 0 + return "Cannot drop object: class not found" + endif + class := aMClassesDesc[j][2] + //?? "CLASS:", class, chr(10) + + dbl := d:select(class,,cmd[3]) + //?? "OBJECT:", dbl,chr(10) + + if len(dbl) == 0 + return "Cannot drop object '"+cmd[2]+' '+cmd[3]+"': object not found" + else + id := dbl[1] + endif + + // Delete metaobject + dbl := d:delete( id ) + //?? dbl, d:error,chr(10) + if .not. empty(d:error) + return "Cannot drop object '"+cmd[2]+' '+cmd[3]+"': object not found" + endif + recover using oErr + return "Error drop '"+cmd[2]+' '+cmd[3]+"': "+oErr:description + end sequence +return NIL + + /* 'CREATE' command */ static function ec_create( self, cmd, res, files ) local oErr, dbh, d:=map(), dict, desc:='', i @@ -1141,10 +1197,11 @@ /* 'SELECT' command */ static function ec_select( self, cmd, res, files ) - local oErr, dbl, d:=self:dep, dict:=self:dict, i + local oErr, dbl, d:=self:dep, dict:=self:dict, i, j local attrs:=array(0), classes:=array(0), where:=array(0) local status:=1, part, o, row, elem, classIds:=array(0) local value, where_condition, field + local item, adAttrs:=array(0), oClass, oAttr, z if dict == NIL return "Open database first" @@ -1183,8 +1240,6 @@ //?? "CLASSES:", classes, chr(10) //?? "WHERE:", where, chr(10) - // TODO: all fields by '*' - if len(classes) == 0 return "Class(es) is not defined" endif @@ -1205,7 +1260,38 @@ aadd(classIds, codb_metaIdByName(dict,i,"CLASS")) next endif - // Second: fill result with 'where' condition check + + // Second: insert all fields instead '*' + for i=1 to len(attrs) + if attrs[i] == '*' + if len(adAttrs) == 0 + for j in classIds + oClass := dict:getValue( j ) + for item in oClass:attr_list + oAttr := dict:getValue( item ) + if ascan(adAttrs, {|e| oAttr:name==e }) == 0 + aadd(adAttrs, oAttr:name) + endif + next + next + endif + attrs[i] := adAttrs + endif + next + adAttrs := array(0) + for i in attrs + if valtype(i) == 'A' + for j in i + aadd(adAttrs, j) + next + else + aadd(adAttrs, i) + endif + next + attrs := adAttrs + //?? "ATTR+:",attrs,chr(10) + + // Third: fill result with 'where' condition check res:fields := attrs res:data := array(0) @@ -1223,7 +1309,7 @@ //?? part,":",len(dbl), dbl,chr(10) if val(d:error) > 0 - return "Cannot get object list for class '"+part+"': "+d:error + return "Cannot get object list for class id '"+part+"': "+d:error endif // Fill attributes columns Index: formatter.prg =================================================================== RCS file: /cvsroot/eas-dev/eas/libcodb_query/formatter.prg,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- formatter.prg 2 Jun 2006 14:32:45 -0000 1.1 +++ formatter.prg 20 Oct 2006 10:30:23 -0000 1.2 @@ -1,9 +1,9 @@ /*-------------------------------------------------------------------------*/ -/* This is part of console client for CODB database */ -/* */ -/* Copyright (C) 2005 by E/AS Software Foundation */ -/* Author: Andrey Cherepanov <sk...@ea...> */ -/* */ +/* This is part of console client for CODB database */ +/* */ +/* Copyright (C) 2005 by E/AS Software Foundation */ +/* Author: Andrey Cherepanov <sk...@ea...> */ +/* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as */ /* published by the Free Software Foundation; either version 2 of the */ Index: Makefile =================================================================== RCS file: /cvsroot/eas-dev/eas/libcodb_query/Makefile,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile 6 Jun 2006 13:29:30 -0000 1.2 +++ Makefile 20 Oct 2006 10:30:24 -0000 1.3 @@ -56,7 +56,7 @@ dist: distclean .prg.o: - $(CLIP) $(CLIPINCLUDE) $< + $(CLIP) -w $(CLIPINCLUDE) $< commit: _cvs commit |