databasenode Properties

The Database node can be used to import data from a variety of other packages using ODBC (Open Database Connectivity), including Microsoft SQL Server, DB2, Oracle, and others.

Example

import modeler.api
stream = modeler.script.stream()
nnode = stream.create("database", "My node")
node.setPropertyValue("mode", "Table")
node.setPropertyValue("query", "SELECT * FROM drug1n")
node.setPropertyValue("datasource", "Drug1n_db")
node.setPropertyValue("username", "spss")
node.setPropertyValue("password", "spss")
node.setPropertyValue("tablename", ".Drug1n")
Table 1. databasenode properties
databasenode properties Data type Property description
mode Table Query Specify Table to connect to a database table by using dialog box controls, or specify Query to query the selected database by using SQL.
datasource string Database name (see also note below).
username string Database connection details (see also note below).
password string  
credential string Name of credential stored in IBM® SPSS® Collaboration and Deployment Services. This can be used instead of the username and password properties. The credential's user name and password must match the user name and password required to access the database
use_credential   Set to True or False.
epassword string Specifies an encoded password as an alternative to hard-coding a password in a script. See the topic Generating an Encoded Password for more information. This property is read-only during execution.
tablename string Name of the table you want to access.
strip_spaces None Left Right Both Options for discarding leading and trailing spaces in strings.
use_quotes AsNeeded Always Never Specify whether table and column names are enclosed in quotation marks when queries are sent to the database (for example, if they contain spaces or punctuation).
query string Specifies the SQL code for the query you want to submit.
Note: If the database name (in the datasource property) contains one or more spaces, periods (also known as a "full stop"), or underscores, you can use the "backslash double quote" format to treat it as string. For example: "{\"db2v9.7.6_linux\"}" or: "{\"TDATA 131\"}". In addition, always enclose datasource string values in double quotes and curly braces, as in the following example: "{\"SQL Server\",spssuser,abcd1234,false}".
Note: If the database name (in the datasource property) contains spaces, then instead of individual properties for datasource, username and password, you can also use a single datasource property in the following format:
Table 2. databasenode properties - datasource specific
databasenode properties Data type Property description
datasource string Format: [database_name,username,password[,true | false]] The last parameter is for use with encrypted passwords. If this is set to true, the password will be decrypted before use.

Use this format also if you are changing the data source; however, if you just want to change the username or password, you can use the username or password properties.