// Execute an SQL statement against the data source func (ds DataSource) ExecuteSQL(sql string, filter Geometry, dialect string) Layer { cSQL := C.CString(sql) defer C.free(unsafe.Pointer(cSQL)) cDialect := C.CString(dialect) defer C.free(unsafe.Pointer(cDialect)) layer := C.OGR_DS_ExecuteSQL(ds.cval, cSQL, filter.cval, cDialect) return Layer{layer} }
func (ds *DataSource) Query(query string) (*Layer, error) { // create select query if it is only a where statement if !strings.HasPrefix(strings.ToLower(query), "select") { layer, err := ds.Layer() if err != nil { return nil, err } layerDef := C.OGR_L_GetLayerDefn(layer.v) name := C.OGR_FD_GetName(layerDef) query = fmt.Sprintf("SELECT * FROM %s WHERE %s", C.GoString(name), query) } queryc := C.CString(query) defer C.free(unsafe.Pointer(queryc)) layer := C.OGR_DS_ExecuteSQL(ds.v, queryc, nil, nil) if layer == nil { return nil, lastOgrError("unable to execute query '" + query + "'") } return &Layer{layer}, nil }