# Execute proc (database query)

Source: https://ref.dm-lang.org/database/query/proc/Execute
Added in BYOND 506.

### Format
> `Execute(database)`

### Args
> database: A /database datum with the database to be queried, or the name of the database file

Runs a database query. Once the query is run, if the query is supposed to returns any rows you can call NextRow() until finished, and then GetColumn() or GetRowData() to get the information from each row. For queries that cause changes, RowsAffected() is also a useful call.

The database argument is optional after the first time you use it.

You can use a filename instead of a /database datum, as a shortcut; the datum will be created for you.

After a query is executed, calling Add() to create new query text will clear out the old query text automatically.

```dm /Execute/
var/database/db = new("mydb.db")
var/database/query/q = new("SELECT quest,complete FROM quests WHERE name=?", usr.key)

if(!q.Execute(db)) return null

var/list/completed_quests = new
while(q.NextRow())
    var/row = q.GetRowData()
    if(row["complete"]) completed_quests[row["quest"]] = 1
return completed_quests
```

### See also
- [database datum](https://ref.dm-lang.org/database/index.md)
- [database query datum](https://ref.dm-lang.org/database/query/index.md)
- [Add proc (database query)](https://ref.dm-lang.org/database/query/proc/Add.md)
- [Close proc (database query)](https://ref.dm-lang.org/database/query/proc/Close.md)
- [GetColumn proc (database query)](https://ref.dm-lang.org/database/query/proc/GetColumn.md)
- [GetRowData proc (database query)](https://ref.dm-lang.org/database/query/proc/GetRowData.md)
- [NextRow proc (database query)](https://ref.dm-lang.org/database/query/proc/NextRow.md)
- [Reset proc (database query)](https://ref.dm-lang.org/database/query/proc/Reset.md)
- [RowsAffected proc (database query)](https://ref.dm-lang.org/database/query/proc/RowsAffected.md)
