1db.execute(1)                 Grass User's Manual                db.execute(1)
2
3
4

NAME

6       db.execute  - Executes any SQL statement.
7

KEYWORDS

9       database, SQL
10

SYNOPSIS

12       db.execute
13       db.execute help
14       db.execute   [-i]    [input=name]     [driver=name]     [database=name]
15       [--verbose]  [--quiet]
16
17   Flags:
18       -i
19           Ignore SQL errors and continue
20
21       --verbose
22           Verbose module output
23
24       --quiet
25           Quiet module output
26
27   Parameters:
28       input=name
29           Name of file containing SQL statements
30
31       driver=name
32           Driver name
33           Options: ogr,dbf,odbc,pg,mysql,sqlite,mesql
34           Default: dbf
35
36       database=name
37           Database name
38           Default: $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/
39

DESCRIPTION

41       db.execute allows the user to execute SQL statements.
42

NOTES

44       db.execute only executes SQL statements and does not return  any  data.
45       If you need data returned from the database, use db.select.
46
47       If  parameters for database connection are already set with db.connect,
48       they are taken as default values and do not need to be  specified  each
49       time.
50
51       If  you have a large number of SQL commands to process, it is much much
52       faster to place all the SQL statements into a text file and use db.exe‐
53       cute's  input file parameter than it is to process each statement indi‐
54       vidually in a loop. If multiple instruction lines are given,  each  SQL
55       line must end with a semicolon.
56
57       Please  see  the  individual  sql  driver pages for how to create a new
58       database.
59

EXAMPLES

61       Create a new table with columns 'cat' and 'soiltype':
62
63       echo 'create table  soils  (cat  integer,  soiltype  varchar(10)  )'  |
64       db.execute
65
66
67       Create a new table using a file with SQL statements:
68
69       db.execute driver=odbc database=g60test input=file.sql
70
71
72       Insert new row into attribute table:
73
74       echo    "INSERT    INTO    nobugs   (id,name,east_gb,north_gb)   values
75       (30,'Ala',1657340,5072301)" | db.execute
76
77
78       Update attribute entries to new value based on SQL rule:
79
80       echo "UPDATE roads SET travelcost=5 WHERE cat=1" | db.execute
81
82
83       Update attribute entries to new value based on SQL rule:
84
85       echo "UPDATE dourokukan SET testc=50 WHERE testc is NULL" | db.execute
86
87
88       Delete selected rows from attribute table:
89
90       echo "DELETE FROM gsod_stationlist WHERE latitude < -91" | db.execute
91
92
93       Add new column to attribute table:
94
95       echo "ALTER TABLE roads ADD COLUMN length double" | db.execute
96
97
98       Column type conversion - update new column from  existing  column  (all
99       drivers except for DBF):
100
101       # 'z_value' is varchar and 'z' is double precision:
102       echo  "update  geodetic_pts SET z = CAST(z_value AS numeric)" | db.exe‐
103       cute
104
105
106       Drop column from attribute table:
107
108       echo "ALTER TABLE roads DROP COLUMN length" | db.execute
109
110
111       Drop table (not supported by all drivers)
112
113       echo "DROP TABLE fmacopy" | db.execute
114
115
116       Update  attribute  with  multiple  SQL  instructions  in  file   (e.g.,
117       file.sql, instruction line must end with a semicolon):
118
119       UPDATE roads SET travelcost=5 WHERE cat=1;
120       UPDATE roads SET travelcost=2 WHERE cat=2;
121
122       cat file.sql | db.execute
123
124

SEE ALSO

126       db.columns, db.describe, db.drivers, db.droptable, db.login, db.select,
127       db.tables, GRASS SQL interface
128

AUTHOR

130       CERL
131
132       Last changed: $Date: 2007-10-09 01:30:41 +0200 (Tue, 09 Oct 2007) $
133
134       Full index
135
136       © 2003-2008 GRASS Development Team
137
138
139
140GRASS 6.3.0                                                      db.execute(1)
Impressum