如何从ns2后端文件执行Sql查询?

时间:2022-06-26 20:13:33

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

是否可以从ns2后端文件执行sql查询?

or is it posible in tcl?

或者它在tcl中是否可行?

1 个解决方案

#1


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.

您当然可以从Tcl执行SQL查询。建议您执行此操作的详细信息取决于您尝试访问的数据库以及您正在使用的Tcl版本。

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.

使用Tcl 8.6,建议您使用TDBC;有许多数据库(SQLite,PostgreSQL,MySQL)的TDBC驱动程序,以及允许访问更多数据库引擎的ODBC。完整的Tcl 8.6发行版也附带SQLite本身。

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.

对于Tcl 8.5和之前的版本,有很多数据库的扩展包,所以很多我都不会列出它们。如果我们知道您要使用哪个数据库,我们就能够为您指出正确的代码。

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.

将包需要视为更高级别的源和负载,这样您就不需要知道包的实现方式或实际位置。它还支持版本控制,因此您可以安装多个版本。这使得管理更新变得更加容易。

#1


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.

您当然可以从Tcl执行SQL查询。建议您执行此操作的详细信息取决于您尝试访问的数据库以及您正在使用的Tcl版本。

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.

使用Tcl 8.6,建议您使用TDBC;有许多数据库(SQLite,PostgreSQL,MySQL)的TDBC驱动程序,以及允许访问更多数据库引擎的ODBC。完整的Tcl 8.6发行版也附带SQLite本身。

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.

对于Tcl 8.5和之前的版本,有很多数据库的扩展包,所以很多我都不会列出它们。如果我们知道您要使用哪个数据库,我们就能够为您指出正确的代码。

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.

将包需要视为更高级别的源和负载,这样您就不需要知道包的实现方式或实际位置。它还支持版本控制,因此您可以安装多个版本。这使得管理更新变得更加容易。