Changeset 63238
- Timestamp:
- Nov 28, 2014, 2:15:16 AM (10 years ago)
- Location:
- grass/trunk
- Files:
-
- 3 edited
-
db/drivers/sqlite/db.c (modified) (1 diff)
-
scripts/v.db.update/v.db.update.html (modified) (4 diffs)
-
scripts/v.db.update/v.db.update.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
grass/trunk/db/drivers/sqlite/db.c
r57276 r63238 111 111 } 112 112 113 /* enable loading of extensions */ 114 sqlite3_enable_load_extension(sqlite, 1); 115 113 116 /* set the sqlite busy handler */ 114 117 sqlite3_busy_handler(sqlite, sqlite_busy_callback, NULL); -
grass/trunk/scripts/v.db.update/v.db.update.html
r56039 r63238 14 14 15 15 <h2>EXAMPLES</h2> 16 17 <h3>Replacing of NULL values</h3> 16 18 17 19 In this example, selectively display lakes without (blue) and with … … 38 40 </pre></div> 39 41 40 Spearfish example: adding new column, copying values from other table 42 <h3>Updating of columns with on the fly calculation</h3> 43 44 Spearfish example: adding new column, copying values from another table 41 45 column with on the fly calculation: 42 46 <div class="code"><pre> … … 47 51 </pre></div> 48 52 53 <h3>Type casting</h3> 54 49 55 Type cast (type conversion) of strings to double precision 50 56 (unsupported by DBF driver): … … 53 59 v.db.update mygeodetic_pts col=zval qcol="CAST(z_value AS double precision)" \ 54 60 where="z_value <> 'N/A'" 61 </pre></div> 62 63 <h3>Updating of columns with on the fly calculation (SQLite extended functions)</h3> 64 65 North Carolina data set example: adding new column, copying values from 66 another table column with on the fly calculation: 67 68 <div class="code"><pre> 69 g.copy vect=precip_30ynormals,myprecip_30ynormals 70 v.db.addcolumn myprecip_30ynormals column="logjuly double precision" 71 v.db.update myprecip_30ynormals column="logjuly" qcolumn="log(jul)" \ 72 sqliteextra=$HOME/sqlite_extensions/libsqlitefunctions.so 73 74 v.db.select myprecip_30ynormals columns=jul,logjuly 75 jul|logjuly 76 132.842|4.88916045210132 77 127|4.84418708645859 78 124.206|4.82194147751127 79 104.648|4.65060233738593 80 98.298|4.58800368106618 81 ... 55 82 </pre></div> 56 83 -
grass/trunk/scripts/v.db.update/v.db.update.py
r63211 r63238 44 44 #%option G_OPT_DB_WHERE 45 45 #%end 46 #%option G_OPT_F_INPUT 47 #% key: sqliteextra 48 #% description: Name of SQLite extension file for extra functions (SQLite backend only) 49 #% gisprompt: old,bin,file 50 #% required: no 51 #%end 46 52 47 53 import sys … … 56 62 qcolumn = options['query_column'] 57 63 where = options['where'] 64 sqlitefile = options['sqliteextra'] 58 65 59 66 mapset = grass.gisenv()['MAPSET'] … … 71 78 database = f['database'] 72 79 driver = f['driver'] 80 81 # check for SQLite backend for extra functions 82 if sqlitefile and driver != "sqlite": 83 grass.fatal(_("Use of libsqlitefunctions only with SQLite backend")) 84 if driver == "sqlite" and sqlitefile: 85 if not os.access(sqlitefile, os.R_OK): 86 grass.fatal(_("File <%s> not found") % sqlitefile) 73 87 74 88 # checking column types … … 94 108 cmd += " WHERE " + where 95 109 110 # SQLite: preload extra functions from extension lib if provided by user 111 if sqlitefile: 112 sqliteload = "SELECT load_extension('%s');\n" % sqlitefile 113 cmd = sqliteload + cmd 114 96 115 grass.verbose("SQL: \"%s\"" % cmd) 97 98 116 grass.write_command('db.execute', input = '-', database = database, driver = driver, stdin = cmd) 99 117
Note:
See TracChangeset
for help on using the changeset viewer.
