-3

Is it possible to execute sql queries from ns2 backend files?

or is it posible in tcl?

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Naveen.S
  • 730
  • 5
  • 21

1 Answers1

1

You can certainly execute SQL queries from Tcl. The details of how you're recommended to do it depend on the database you're trying to access and the version of Tcl you're using.

With Tcl 8.6, you're advised to use TDBC; there are TDBC drivers for a number of databases (SQLite, PostgreSQL, MySQL) and also for ODBC which allows access to many more database engines. Full Tcl 8.6 distributions also come with SQLite itself.

With Tcl 8.5 and before, there are extension packages for many databases, so many that I'm not going to list them. If we knew which database you were looking to use, we'd be able to point you to exactly the right piece of code to do it.

In all cases, your code is going to do something like this:

# Optionally, if needed...
lappend auto_path /the/location/of/the/extension/packages

# Make the code of the package available to your code
package require theDatabaseInterface

# The syntax of this will vary a lot...
theDatabaseInterface connect dbhandle "dbproto://user:pass@host/thedb"
dbhandle query {
    SELECT ...
}

Think of the package require as being a higher-level of source and load, so that you don't need to know about how the package is implemented or where it is actually located. It also supports versioning, so you can have multiple versions installed. That makes managing updates much easier.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215