Primavera SDK Programmer's Guide

27
2/9/12 PUimaYeUa SDK PUogUammeU'V GXide 1/27 VhaffeUaVVoc.neW/PUogUammeU'V GXide.hWm Primavera Software Development Kit Programmer¶s Guide Table of Contents OY H U Y L H Z IQWHUIDFHV S XSSRUWHG SSHFLDO BX V LQHVV FXQFWLRQV PURJUD P PDWLF AFFHVV PULPDYH U D S D K DQG MXOWL-XVHU AFFHVV CRQFXUUHQF\/LLFHQVLQJ IVVXHV ZLWK PULPDYHUD SDK ODBC DSN SHWXS WRUNLQJ ZLWK WKH ODBC DDWD SRXUFH AGPLQLVWUDWRU DHOD\HG LRDGLQJ RHDG RQO\ DFFHVV WR WKH PULPDYHUD SDK GOREDO DQG PURMHFW SF R SH LHYHO AFFHVV LHYHO T D EOHV E[WHQGH G T DEOHV MHWD T DEOHV OA TD E OHV SWRUHG PU R F H GXUHV SSHFLDO NRWHV IRU USGDWLQJ FRUHLJQ KH\V PULPDYHUD SDK EUURU C R GHV SELECTV, INSERTV, UPDAT E V DQG DELETEV FLOHV LQVWDOO H G E \ WKH PULP D YHUD SRIWZDUH DHYHORSPHQ W KLW (SDK) WRUNLQJ ZLWK WKH PULPD Y HUD SDK (E[DPSOHV) GHQHULF E[DPSO H V ( S QL) CUHDWLQJ DQ EQWHUSULVH PURM H FW SWUXFWXUH (EPS) QRGH CUHDWLQJ D PU R MHFW CUHDWLQJ D W B S QRGH CUHDWLQJ D TDVN CUHDWLQJ D R H VRXUFH CUHDWLQJ D RHVRXUFH AVVLJQ P HQW CUHDWLQJ TDVN DHSH Q GHQFLHV CUHDWLQJ D C D OHQGDU CUHDWLQJ DQ AF W LYLW\ CRGH CUHDWLQJ D UVHU AFWLYDWLQJ BDV H OLQHV I RU LRDGH G PURMHFW MS AFFHVV E [ D PSOH VLVXDO BDVLF/A D O E [DP S OH AFWLYHX DDWD OEM H F WV (ADO) LRWXV NRWHV E [ DPSOH MLFURVRIW WLQGRZV S F ULSWLQJ HRVW (WSH)/ADO E[DPSOH JDYD E[DPSOH ( X VLQJ J D BC-ODBC) PULPDYHU D S D K L R J FLOH(V) SQL (DJJUHJDWH / V FDODU) IXQFWLRQV VXSSRUWHG E\ WKH PULPDYHUD SDK/OA F A Q TU R X EO H VK R RWLQJ DRFXPHQWD W LRQ/URL S R X UFHV OYHUYLHZ (return to Ta b le of Contents) TKLV GRFXPHQW GHVFULEHV KRZ WR DFFHVV WKH PULPDYHUD SRIWZDUH DHYHORSPHQW KLW (SDK). TKH PULPDYHUD SDK PDNHV PURMHFW MDQDJHPHQW GDWD DYDLODEOH WR H[WHUQDO DSSOLFDWLRQV. IQ DGGLWLRQ WR GDWD, WKH PULPDYHUD SDK SURYLGHV DSSOLFDWLRQ EXVLQHVV UXOHV DQG FDOFXODWHG YDOXHV WKDW IDFLOLWDWH LQWHJUDWLRQ ZLWK FXVWRPHU GDWDEDVHV DQG DSSOLFDWLRQV. TKH PULPDYHUD SDK PDNHV PULPDYHUD GDWD DYDLODEOH YLD DQ OSHQ DDWDEDVH CRQQHFWLYLW\ (ODBC) W\SH LQWHUIDFH DQG LV DOVR FRPSDWLEOH ZLWK DQ\ ODBC FOLHQW. ODBC FOLHQWV LQFOXGH SURJUDPPLQJ ODQJXDJHV VXFK DV VB, PRZHUBXLOGHU, C++, VFULSWLQJ WRROV, DQG VR RQ. TKH SDK UHTXLUHV VRPH H[SHUWLVH LQ H[WUDFWLQJ GDWD IURP D GDWDEDVH (W\SLFDOO\, XVLQJ SWUXFWXUHG QXHU\ LDQJXDJH (SQL) TXHULHV RU SURJUDPPLQJ WRROV), DORQJ ZLWK VRPH NQRZOHGJH RI WKH DSSOLFDWLRQ VFKHPD (WDEOHV DQG ILHOGV). TKH SDK VXSSRUWV ERWK UHDG DQG ZULWH RI PULPDYHUD GDWD. PK\VLFDO SFKHPD YV. LRJLFDO SFKHPD (return to Table o f Contents) TKH SK\VLFDO VFKHPD LV WKH VFKHPD DW WKH GDWDEDVH OHYHO. TKH SK\VLFDO GDWD PRGHO VSHFLILHV LPSOHPHQWDWLRQ GHWDLOV WR PDWFK IHDWXUHV RI D SDUWLFXODU

Transcript of Primavera SDK Programmer's Guide

Page 1: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

1/27shafferassoc.net/Programmer's Guide.htm

Primavera Software Development Kit Programmer’s Guide Table of Contents OverviewInterfaces SupportedSpecial Business FunctionsProgrammatic AccessPrimavera SDK and Multi-user AccessConcurrency/Licensing Issues with Primavera SDKODBC DSN SetupWorking with the ODBC Data Source AdministratorDelayed LoadingRead only access to the Primavera SDKGlobal and Project Scope LevelAccess LevelTables Extended Tables Meta Tables OA TablesStored ProceduresSpecial Notes for Updating Foreign KeysPrimavera SDK Error CodesSELECTs, INSERTs, UPDATEs and DELETEsFiles installed by the Primavera Software Development Kit (SDK)Working with the Primavera SDK (Examples) Generic Examples (SQL) Creating an Enterprise Project Structure (EPS) node Creating a Project Creating a WBS node Creating a Task Creating a Resource Creating a Resource Assignment Creating Task Dependencies Creating a Calendar

Creating an Activity CodeCreating a User

Activating Baselines for Loaded Project MS Access Example Visual Basic/ADO Example ActiveX Data Objects (ADO) Lotus Notes Example Microsoft Windows Scripting Host (WSH)/ADO Example Java Example (using JDBC-ODBC)Primavera SDK Log File(s)SQL (aggregate/scalar) functions supported by the Primavera SDK/OAFAQTroubleshootingDocumentation/URL Sources

Overview (return to Table of Contents)

This document describes how to access the Primavera Software Development Kit (SDK). The Primavera SDK makes Project Management data availableto external applications. In addition to data, the Primavera SDK provides application business rules and calculated values that facilitate integration withcustomer databases and applications. The Primavera SDK makes Primavera data available via an Open Database Connectivity (ODBC) type interface and is also compatible with any ODBCclient. ODBC clients include programming languages such as VB, PowerBuilder, C++, scripting tools, and so on. The SDK requires some expertise inextracting data from a database (typically, using Structured Query Language (SQL) queries or programming tools), along with some knowledge of theapplication schema (tables and fields). The SDK supports both read and write of Primavera data.

Physical Schema vs. Logical Schema (return to Table of Contents)

The physical schema is the schema at the database level. The physical data model specifies implementation details to match features of a particular

Page 2: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

2/27shafferassoc.net/Programmer's Guide.htm

product, as well as configuration information for that database instance. For example, when you run the database setup scripts, Oracle and SQL Serverrequire different SQL scripts. The logical data model of the database is independent of the eventual target database (Oracle/SQL Server.) The logical schema is exposed as anormalized, in-memory representation of data. The logical schema is similar to the physical schema, but does contain some differences. For example,calculated fields such as Earned Value may be included in the logical schema, but they are not stored directly in the physical schema. These fields arecalculated in memory and are accessible via the Primavera SDK.

Interfaces Supported (return to Table of Contents)

ODBC technology provides a common interface for accessing heterogeneous SQL databases. ODBC is based on SQL as a standard for accessing data.This interface provides maximum interoperability: a single application can access different SQL Database Management Systems (DBMS) through acommon set of code. This enables a developer to build and distribute a client/server application without targeting a specific DBMS. Database drivers arethen added to link the application to the user's choice of DBMS. Since ODBC is supported, other third-party bridges such as OLEDB and JDBC also provide access. ODBC Open Database Connectivity (ODBC) technology provides a common interface for accessing heterogeneous SQL databases. ODBC is

based on Structured Query Language (SQL) as a standard for accessing data. This interface provides maximum interoperability: asingle application can access different SQL Database Management Systems (DBMS) through a common set of code. This enables adeveloper to build and distribute a client/server application without targeting a specific DBMS. Database drivers are then added to linkthe application to the user’s choice of DBMS.

OLEDB OLEDB is a set of interfaces that expose data from a variety of sources by using the Component Object Model (COM). OLEDB interfaces

provide applications with uniform access to data stored in diverse information sources. These interfaces support the amount of DBMSfunctionality appropriate to the data store, enabling the data store to share its data. In addition we may choose to expose custominterfaces to enable clients to access functionality beyond data manipulation. It’s really up to us, we may choose to expose some/allfunctionality. These additional interfaces can co-exist with the interfaces required by OLEDB. This may be accomplished via COMaggregation or containment.

JDBC JDBC is intended to be a low-level API that supports basic SQL functionality. The authors of JDBC expect higher-level APIs to be defined

and possibly implemented on top of JDBC.

Special Business Functions (return to Table of Contents)

In cases where special business functions need to be exposed via the ODBC interface, stored procedures are used to allow the client to invoke functionsnot directly related to data manipulation. For example, a client may use "EXEC SQL call create_project(wbs_id, 'APEX' );" to add a project to thedatabase via the ODBC interface. The number of cases where these hooks are required is fairly small, and the stored procedure model accomplishes itwell. All other business logic pertaining to data update is built into the ODBC interface, much like triggers are built into a traditional physical database.

Programmatic Access (return to Table of Contents)

The examples provided in this document use MS ActiveX Data Objects (ADO) for data access. ADO offers a simple object model that exposesconnections upon which to execute and return record sets and field values. This method for accessing data can be used via Visual Basic, C++, JScriptand many other popular programming languages. The SQL queries provided in this document are applicable to other ODBC tools as well.

Primavera SDK and Multi-user Access (return to Table of Contents)

Primavera SDK has a table called USESSION. This table typically shows only the row associated with the current session. Users are prevented frominserting or deleting data from this table, as it is only for reference. Note that the underlying physical database shows one row for each logged on user,but these are not shown via the Primavera SDK interface. The Primavera SDK obeys all multi-user rules and can be used in a multi-user environment where many PM tools access the database at the same time.The Primavera SDK does not, however, support more than one connection to a Primavera SDK data source on any given client machine. Opening asecond connection cancels the license slot granted to the first client, and both clients may become unstable.

Concurrency/Licensing Issues with Primavera SDK (return to Table of Contents)

A client program using the Primavera SDK driver participates in the same concurrency mechanism as other Project Management client programs. Otherapplications are notified of changes made via the Primavera SDK driver, and the Primavera SDK is able to detect when changes are made to theunderlying data by other applications. The mechanism for updating the client's view of the new data via Primavera SDK is invoked via ODBC by a storedprocedure called refresh(). The refresh() stored procedure can be invoked at any time during the life of an active Primavera SDK connection. If “stale” data does not exist, the

Page 3: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

3/27shafferassoc.net/Programmer's Guide.htm

refresh call does nothing. It is recommended that the Primavera SDK programmer invoke the refresh() procedure every few minutes while the clientapplication is active. It does not matter how often data is refreshed. The decision to refresh the data is up to the individual client and programmer anddepends on how often the application needs to see updated data. Note that for some operations, the Primavera SDK driver will invoke the refresh() onits own. Additionally, Primavera SDK periodically updates its "last active" timestamp in the underlying database for licensing purposes. This process runsautomatically in the background for an active Primavera SDK connection and does not require any special handling by the programmer.

ODBC DSN Setup (return to Table of Contents)

The Primavera SDK can be used as a stand-alone application without other Primavera client applications. The standard SDK setup installs the BorlandDatabase Engine (BDE) if it does not already exist on the system. Like other ODBC drivers, the Primavera SDK requires an ODBC Data Source to be setup with the Primavera SDK driver before the data can be accessed. The SDK installation adds an ODBC driver named Primavera SDK to the system. The setup process also prompts the user to create a database alias andcreates a System DSN to access the SDK. The default values can be modified at any time. The following parameters are required during the DSN setup for the SDK to function properly:ODBC Name: The name the user sees in the ODBC System Data Sources.Database Alias: The database alias used by BDE to connect to the database (defined by the user during SDK setup). System and User Requirements:

Installing Primavera SDK on Windows NT and Windows 2000 requires administrative rights.System requirements are the same for SDK as for other Primavera applications.

Working with the ODBC Data Source Administrator (return to Table of Contents)

To edit/add/remove a Primavera SDK data source, use the ODBC Data Source Administrator found in Control Panel. In Control Panel you should have a ‘Data Sources (ODBC)’ icon.Double-click on this icon to start the ODBC Data Source Administrator. (Windows XP, 2000 users go to ‘Administrative Tools’ in Control Panel.)

Page 4: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

4/27shafferassoc.net/Programmer's Guide.htm

In the ODBC Data Source Administrator, if you click on the ‘System DSN’ tab you will see the data source thatwas added during the installation of the Primavera SDK. Use this dialog box to Add/Remove/Configure yourPrimavera SDK data sources.

If you need to add an additional Primavera SDK data source, you simply click the ‘Add’ button in thedialog box above and select the ‘Primavera Software Development Kit’ as the driver for your data source.

You will then be given the following dialog to complete, just as you are during the installation of the Primavera SDK.

Page 5: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

5/27shafferassoc.net/Programmer's Guide.htm

Delayed Loading (return to Table of Contents)

Delayed Loading is a mechanism for loading global data only when it is requested. The installation of Primavera SDK installs PMSDK.ini file in the\Primavera Common\PMSDK\Engines folder where delayedLoadMode can be turned ON or OFF. By default delayedLoadMode is turned ON. Withdelayed loading ON, the time to establish a connection is reduced due to the fact that not all of the global data is loaded into memory. Also,response/loading time is reduced when updating the scope_level for projects since only global data associated with that project is loaded.��

Read only access to the Primavera SDK (return to Table of Contents)

Users that log into the Primavera SDK can be configured so that they are restricted from making edits and have read-only access to all global andproject data.This can be accomplished by creating a global profile under Admin, Security Profiles with the global privilege View All Global/Project Data via SDK set. Auser thatlogs in via the Primavera SDK with a global profile and this global privilege set will have read-only access. For Example:

Page 6: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

6/27shafferassoc.net/Programmer's Guide.htm

A user that logs into the Primavera SDK with read-only access is able to update the following fields:Table: Field: Explanation: Sample:

PROJECT scope_level Necessary to load project leveldata, but data will be read-only

U D P A T E P R O J E C TS E T s c o p e _ l e v e l = 7W H E R E p r o j _ i d = 3 1 4

PROJBASE current_baseline_flag (primary)current_baseline_flag1(secondary)current_baseline_flag2 (tertiary)

Sets the current SDK session userbaseline for a given project.

U P D A T E P R O J B A S ES E T c u r r e n t _ b a s e l i n e _ f l a g = ‘ Y ’W H E R E p r o j _ i d = 1 2 3

PROJBASE project_is_project_baseline_flag Sets the baseline as the projectbaseline for a given project.

U P D A T E P R O J B A S ES E T p r o j e c t _ i s _ p r o j e c t _ b a s e l i n e _ f l a g =‘ Y ’W H E R E p r o j _ i d = 1 2 3

SYSOPTIONS curr_id Sets the view currency to be usedfor monetary field types

U P D A T E S Y S O P T I O N SS E T c u r r _ i d = 1 1

SYSOPTIONS spread_interval Sets the spread interval to beused by the *_SPREADS tables --values are Year, Quarter, Month,Week, Day, and Hour. Default is‘M’.

U P D A T E S Y S O P T I O N SS E T s p r e a d _ i n t e r v a l = ‘ W ’

Global and Project Scope Level (return to Table of Contents)

By default, when a user opens a connection to the Primavera SDK (via ODBC) using the Project Management engine, the global data are loaded (forexample Resource Pool and Reports), but the project-specific data are not loaded (for example WBS, Activities and Resource Assignments). To load project data, the application programmer must indicate to the driver the name and location of the projects to load. This is accomplished byupdating a logical field in the PROJECT table called scope_level. The higher the scope_level value, the more detail is loaded. When the driver loads, all projects are at scope_level 1, which includes only information about the project itself, no details about its structure orcontents. When clients want to see project level details, they must increment the scope_level for those projects from 1 to 7. For example:

U P D A T E P R O J E C T S E T s c o p e _ l e v e l = 7 W H E R E p r o j _ i d I N ( 1 5 1 , 2 0 9 , 3 0 0 5 )

loads detail data for those three projects. If the database is small, the programmer may choose to load more, or even all project data. If the projectsare numerous and large, the client may load only a few projects at a time. Updating the scope_level from 7 to 2 causes the driver to unload the dataand frees up memory for other projects. This process is similar to loading (opening) projects in the Project Management application when you first logon to the Windows version. The following scope levels are available:Title Scope Level Description

SCOPE_LEVEL_PROJECT_ONLY 1 Only root WBS - User has security to view this project's root WBS detail

Page 7: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

7/27shafferassoc.net/Programmer's Guide.htm

information

SCOPE_LEVEL_MAX_WBS 2 WBS up to the max WBS level that is specified for the Summarizer

SCOPE_LEVEL_ALL 7 All activities, documents, and other information

Access Level (return to Table of Contents)

Along with setting the scope level, the access level must also be set when opening a project. Three types of access levels are available: Read Only,which is the default, Shared, and Exclusive. Read Only does not allow any data to be updated. To update data, the scope level must be set to Sharedwhich opens a shared copy of the project, or Exclusive, which opens a master copy of the project, locking out all other users. The setting for each levelis defined in the following table: Access Level Setting

Read Only 0

Shared 1

Exclusive 2

Tables (return to Table of Contents)

A listing of all of the tables exposed by the Primavera SDK is provided in the included GeneralTable&Fields.htm file. This file provides a list of tables witha general description of the data stored in that table. The table names provide a hotlink to detailed table information including field name, field type,maximum length, read-only, nullable, time distributed, and description.

Extended Tables (return to Table of Contents)Extended tables are offered to allow for optimized joins. For example, the table X_TASK offers the TASK table fields (task_id toactv_code_contractor_code_id) and adds extended information including PROJWBS, PROJECT, RSRC, and CALENDAR, as well as extended activity codeinformation. The extended tables are available for selecting data. Client programmers are strongly encouraged to use the extended columns in place ofcreating traditional table joins in SQL. This mechanism providea much better performance. An example of traditional joins versus extended columns is as follows: Query Using Traditional Joins:

SELECT t.task_name, r.rsrc_nameFROM task t, rsrc r, taskrsrc trWHERE t.task_id = tr.task_idAND r.rsrc_id = tr.rsrcid

Query Using Extended Columns:

SELECT TASK__task_name, RSRC__rsrc_name FROM x_taskrsrc

Note the following features of using extended columns:1)������Extended column queries always have only one table in the FROM-clause -- it should be the primary relationship you are querying.

2)������Extended column queries reference other joined tables via the syntax: <joined_table_name>__<column_name>. The system utilizes the

pre-indexed foreign keys internally, and does not require the programmer to specify the join relationships. 3)������Avoid using ‘SELECT * FROM X_<table>’ when working with Extended tables. Extended tables can have a number of columns that exceed the

limit that the client being used can support. To prevent exceeding client limitations, construct efficient SQL statements like: SELECT TASK__task_name, RSRC__rsrc_name FROM x_taskrsrc when using extended tables.

Meta Tables (return to Table of Contents)Meta tables are logical tables that describe information about the structure and status of the (logical) database. SYSTABLES

contents: lists one row per table for other logical tablesexample columns: api_table_name, table_title, guid_field, import_optionsspecial fields: last_assigned_key (integer), identifies the last generated primary key for this table

SYSCOLUMNS

contents: lists one row per field across all logical tablesexample columns: api_table_name, field_name, data_type, field_length, read_only_flag

SYSOPTIONS

The SYSOPTIONS table is used primarily for reference by programmers and testers. It contains only one row, and has no reflection in the

Page 8: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

8/27shafferassoc.net/Programmer's Guide.htm

physical database. Only one field is updatable, and the rest are read-only (see the following table).

Column Name Valid Values Meaning

Id 1 (readonly) primary key

engine_type <string> (readonly) internal object type and suite identifier for driver

engine_version <integer> (readonly) build number of driver engine (matches GUI build number)

physical_database <string> (readonly) identifies physical database (BDE alias name) of underlying database and itsnative driver type

client_filename <string> (readonly) full path/filename of active client program

driver_filename <string> (readonly) full path/filename of driver DLL

spread_interval "Y", "Q", "M", "W", "D", "H" selects which date bin type should be reported in the *_SPREADS tables --values are Year, Quarter, Month, Week, Day, and Hour (where available).Default is "M"

curr_id <integer> selects the view currency to be used for monetary field types(a valid curr_id value from the CURRTYPE table)

Examples:

S E L E C T e n g i n e _ v e r s i o n F R O M S Y S O P T I O N S

(shows the release number of the driver)

U P D A T E S Y S O P T I O N S S E T s p r e a d _ i n t e r v a l = ' W '

(changes your date bin type to Weekly, as seen in all the _SPREADS tables)

OA Tables (return to Table of Contents)The OA tables are read-only system tables that describe the SDK schema. These tables can be used in conjunction with the meta tables to access usefulinformation about available tables, fields, and stored procedures exposed through the Primavera SDK. Table Name Description

OA_TABLES Description of all the tables in the database.

OA_COLUMNS Descriptions of columns for all the Tables in the database.

OA_TYPES Data types supported by OPENRDA DAM Databases (needed in ODBC 1).

OA_INFO Data Source information (needed in ODBC level 1).

OA_STATISTICS Index information of all tables in the database.

OA_FKEYS Foreign Key information of all tables in the database.

OA_PROC Description of all the procedure names in the database.

OA_PROCCOLUMNS Descriptions of input and output parameters and columns that make up result set for specifiedprocedures.

Stored Procedures (return to Table of Contents)

A number of stored procedures are available via the Primavera SDK interface. These stored procedures are not related to the physical database -- theyare logical procedures that operate at the level of business rules and are implemented in code, in the driver. They are provided primarily as shortcuts --most of their functionality can be implemented by executing various SQL queries against the logical schema. Note: Stored procedures in the Primavera SDK do not return values, nor

do they return result sets. These may be supported in the future.

Stored Procedure Description

create_project(wbs_id, proj_short_name ) Inserts a new row into PROJECT and PROJWBS tables. The project is addedunder the specified EPS node (the wbs_id). Check last_assigned_key fromSYSTABLES to get the newly assigned proj_id and wbs_id (see above).

copy_project(proj_id, copy_options) proj_id is an integer that is not null.Copy_options is a string upto 512 characters can be null.

delete_project(proj_id ) Cascades to all related information including baselines.

create_eps(parent_wbs_id, wbs_short_name) Parent_wbs is an integer that is not null.wbs_short_name is a string up to 20 characters that is not null.EPS is a superset of the WBS values.

delete_eps(proj_id) If the EPS node has other child EPS nodes or projects under it, then thedelete_eps stored proc fails. Users first have to delete the projects and otherchild EPS nodes before deleting the EPS node.

commit_changes Updates the database on demand.

refresh Refreshes the in memory table list. copy_project parameters:

proj_id (Integer, Not Null)copy_options (string, 512 chars, Nullable)

Page 9: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

9/27shafferassoc.net/Programmer's Guide.htm

copy_options above is a string that contains all the options of what should and should not be copied (the default is False, or "don't copy"). A developer may use the following constants to concatenate and define the copy options:Value Descriptions

copy_document Copies project assigned documents.

copy_riskthrs Copies project assigned Risks and Thresholds.

copy_projissu Copies project assigned Issues.

copy_reports Copies project assigned Reports.

copy_ext_dependencies Copies the external dependencies. For example... procedure MyProc()var sCopyOptions: String; begin sCopyOptions := “copy_document=Y;copy_riskthrs=Y;copy_projissu=N”;end; sCopyOptions above copies the Documents and Risks/Thresholds but does not copy Project Issues, as specified.Reports and External Dependencies are not copied via the default value. Uppercase values must be used to copy project data. Anything other than an uppercase Y resultsin data not being copied.

Special Notes for Updating Foreign Keys (return to Table of Contents)

Foreign keys for certain tables cannot be updated via the Primavera SDK interface. The most common example is the proj_id field for a row that has aforeign key to the PROJECT table. Since changing the proj_id on a row (for example, a row in the TASK table) removes the task from one project andadds it into a different project, this operation involves more complex logic that is not invokable via the Primavera SDK. Some of these operations(moving items from one project to another) are supported by the Windows applications, but not via the Primavera SDK, since more contextualinformation is available when using the Windows products. For example, when moving an activity from one project to another, the Windows product can detect exactly where in the WBS tree (or other groupings)you are placing the task and assign the new attributes accordingly. In the Primavera SDK, however, that context is not present, and the operation wouldhave to make many assumptions about the programmer's intent. Accordingly, if you want to update certain foreign keys (like proj_id) via thePrimavera SDK, it is recommended that you INSERT (make a new row) and then DELETE (remove the old row) instead.

Primavera SDK Error Codes (return to Table of Contents)

This table outlines the error codes returned by the Primavera SDK ODBC driver. Note that other error codes may be returnedby ODBC/OLE/COM from the driver under some conditions. All error conditions are returned with a detailed description string.Error Description

S_OK 0x00000000 // success

E_NOTIMPL 0x80004001 // function not implemented

E_FAIL 0x80004005 // low level failure

E_UNEXPECTED 0x8000FFFF // unexpected result

PMSDK_E_INTERNALERR 0x80040003 // internal driver error

PMSDK_E_NOCONNNECTION 0x80040010 // driver not connected, operation not allowed

PMSDK_E_BAD_LOGON 0x80040011 // username/password or license invalid

PMSDK_E_BAD_TABLENAME 0x80040020 // invalid table name

PMSDK_E_BAD_FIELDNAME 0x80040021 // invalid field/column name

PMSDK_E_BAD_PROCNAME 0x80040022 // invalid stored procedure name

PMSDK_E_NOTNULL 0x80040030 // missing required value for field

PMSDK_E_READONLY 0x80040031 // insert/update/delete on read-only value/row

PMSDK_E_PROCFAIL 0x80040032 // stored procedure returned error

PMSDK_E_NONNEGATIVE 0x80040033 // negative value not allowed

PMSDK_E_VALUERANGE 0x80040034 // value outside of valid range

PMSDK_E_FORMAT 0x80040035 // value has invalid format

PMSDK_E_INVALIDVAL 0x80040037 // value for this field is not a valid in context

PMSDK_E_NOTUNIQUE 0x80040036 // value must be unique

Page 10: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

10/27shafferassoc.net/Programmer's Guide.htm

SELECTs, INSERTs, UPDATEs and DELETEs (return to Table of Contents)

Selects of Data - Selects from a table:

The table TASK contains several fields starting with task_id:

S Q L > S E L E C T t a s k _ i d , t a s k _ n a m e F R O M T A S K

task_id task_name===============31773 Perform system integration and testing31774 Prepare for system integration and testing31778 Perform QA testing of system13783 Install the system

Selects of Data - Selects from an extended table:

The table X_TASK provides extended activity information. Use X_TASK table to quickly get a list of tasks and determine the location of the taskin the WBS, along with the resource assigned to the task.

S Q L > S E L E C T t a s k _ i d , P R O J W B S _ _ w b s _ s h o r t _ n a m e , R S R C _ _ r s r c _ s h o r t _ n a m e F R O M X _ T A S K

task_id PROJWBS__wbs_short_name RSRC__rsrc_short_name=====================================================31773 IT BMCA31774 IT BMCA31778 QA BMCA13783 SI JSAN

Inserts and Assignment of Primary Keys:In a typical physical SQL database, the client is responsible for assigning primary keys to new rows (INSERT). With the Primavera SDK, the client is notallowed to assign primary keys, since primary keys must go through the concurrency layer and not conflict with any other users on the system. Therefore, all INSERT statements to tables having a single primary key (see the schema doc for more information) should provide a primary key fieldwith a value of zero. The actual primary key is assigned by the driver, and the client can query for it immediately after the INSERT call. To determine the value of a primary key on a new row, use the SYSTABLES table and look for the corresponding last_assigned_key field. Example: S Q L > I N S E R T I N T O U S E R S ( u s e r _ i d , p r o f _ i d , a c t u a l _ n a m e ) V A L U E S ( 0 , 1 2 , ' B o b S m i t h ' )

1 row inserted. S Q L > S E L E C T l a s t _ a s s i g n e d _ k e y F R O M S Y S T A B L E S W H E R E a p i _ t a b l e _ n a m e = ' U S E R S '

last_assigned_key ================= 188

The following table lists the fields required when inserting a row into a table: Table Name Required Fields

ACTVCODE actv_code_type_id

BUDGCHNG proj_id, wbs_id

CALENDAR clndr_type

DOCUMENT proj_id

EXTAPP login_supply_flag, app_name,app_exe_name

ISSUHIST proj_id,issue_id

PCATVAL proj_catg_type_id

PROJCOST task_id, cost_per_qty

PROJFUND fund_id, proj_id

PROJISSU proj_id,add_by_name

PROJPCAT proj_catg_type_id, proj_catg_id

PROJRISK proj_id

PROJWBS proj_id

Page 11: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

11/27shafferassoc.net/Programmer's Guide.htm

RCATVAL rsrc_catg_type_id

RISKCTRL proj_id, risk_id

RSRCRATE rsrc_id

RSRCRCAT rsrc_catg_type_id, rsrc_catg_id,rsrc_id

RSRCROLE role_id,rsrc_id

TASK wbs_id

TASKACTV actv_code_type_id, actv_code_id

TASKDOC proj_id, task_id, doc_id, wbs_id

TASKMEMO task_id, memo_type_id, proj_id

TASKPRED task_id, pred_task_id, pred_type

TASKPROC task_id

TASKRSRC task_id, rsrc_id

TSDATES start_date, end_date

USEROBS obs_id,user_id,prof_id

USERS prof_id, actual_name

WBSBUDG proj_id or wbs_id

WBSMEMO proj_id, memo_type_id, wbs_id

WBSSTEP proj_id, wbs_id, step_name

Updating DataTo modify an existing record, the SQL command Update can be used as follows:

S Q L > U P D A T E T A S K S E T t a s k _ n a m e = ' D o c u m e n t I n f r a s t r u c t u r e ' W H E R E t a s k _ c o d e = ' A 1 0 0 0 '

When updating data, use the primary key to avoid accidentally changing data. Activity IDs should be unique within a project, but the Primavera SDKallows multiple projects to be opened. The following command ensures that only one record is updated:

S Q L > U P D A T E T A S K S E T t a s k _ n a m e = ' D o c u m e n t I n f r a s t r u c t u r e ' W H E R E t a s k _ i d = 3 1 7 7 3

� Deleting DataTo remove records from a table, use DELETE. For items that require many business rules to fire, a stored procedure is available that handles deletion ofchildren and associated records to ensure data integrity. Refer to the following example of deleting with a specified wildcard:

S Q L > D E L E T E F R O M U S E R S W H E R E u s e r _ i d = 7 8 9 6

Field Type/Data Type MappingsThe generated HTML tables contain a column called field type. Thefollowing table lists the data types that map to all fields in the system.

Field Type Data Type

Primary Key Integer

Foreign Key Integer

Sequence Integer

Text String

Currency Double

Yes/No String

HTML Memo

Start Date Date Type

Integer Integer

Static String

GUID String

Duration Double

Floating Double

2 Decimals Double

Rsrc Cost/Qty Double

Finish Date Date Type

Quantity Double

Percent Double

Variant Double

Date Range String

Page 12: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

12/27shafferassoc.net/Programmer's Guide.htm

Price/Qty Double Special Note for Setting End-Date Fields via the SDK:There is a special consideration when assigning end-date values that fall on day boundaries via the SDK. When assigning an end date value that fallsexactly on a day boundary, use the date of the following day, and omit the time value or use midnight. This only applies when assigning a value to anend date field, which includes activity end date (TASK table) as well as end dates in the TASKRSRC, PROJWBS, PROJECT, and other tables. For example, if a task starts on Jan 10th, Monday, and ends on Jan 12th, Wednesday, the task lasts for exactly three days. The end date should be"1/13/2001 00:00". This will be displayed in the GUI as "1/12/2000", since midnight of the following day is interpreted as ending on the previous day'sdate. If you are specifying a mid-day timestamp, there is no need to increment the end-date's day.

Files installed by the Primavera Software Development Kit (SDK)(return to Table of Contents) The ‘\Primavera Common\PMSDK’ contains several sub-folders: ‘\Primavera Common\PMSDK\Cache’ - (not used) ‘\Primavera Common\PMSDK\Doc’ - contains SDK HTML documentation files index.html - root HTML help file

GeneralTables&Fields.htm - detailed listing of tables/fields exposed via the SDK Programmer's Guide.htm - detailed documentation on using the SDK SpreadTables&Fields.htm - detailed listing of spread tables StaticFieldsDefinitions.htm - detailed listing of static values used in the SDK ExtendedTables&Fields.htm - summary listing of Extended tables SYSTABLES.htm - meta table in html format SYSCOLUMNS.htm - meta table in html format SYSOPTIONS.htm - meta table in html format ‘\Primavera Common\PMSDK\Driver’ - contains the Open Access (C++) driver datatype.dbf - configuration database used by Open Access drivinfo.dbf - configuration databasefor Data Access Manager (DAM) for Open Access; parameters are extracted/set in the oainfo.ini file.

EngineProperties.dll - The DLL which contains the UI for the DSN setup dialog oadrd.ini - contains connection properties as they are created oainfo.ini - Data Access Manager (DAM) settings used by Open Access oaisql.lic - driver license file OpenRDA.ini - Open Access server configuration file PrmDPAPI.dll - Primavera ODBC Data Provider for WIN32 (main driver file) ‘\Primavera Common\PMSDK\Engines’ - contains the main engine file(s) and the SDK configuration file PMSDK.dll - main engine file (dll) PMSDK.ini - used to set delayedLoadMode

Working with the Primavera SDK (Examples) (return to Table of Contents)

Generic Examples (SQL) (return to Table of Contents) When a connection is established with the Primavera SDK Data Source, the scope_level in the project table is set to 1 by default. This permits access toglobal data. Subsequently, as the scope_level is increased from 1 to 7, detailed data are loaded in memory. In addition to setting the scope_level,project data must be accessed with the appropriate access permissions. The access_level should be set to either 1 (shared mode) or 2 ( exclusivemode) to modify project-related data. Creating an Enterprise Project Structure (EPS) node (return to Table of Contents)To view EPS data, default scope_level of 1 is sufficient. An EPS node is always created under another EPS node. To create a lower-level EPS node, thewbs_id of another EPS node as the parent_wbs_id. The PROJWBS table flags each entry as a PROJECT, EPS, or WBS node in the node_type field. Since the root EPS node does not have a parent, it can be accessed from the PROJWBS table using the following query:

S E L E C T w b s _ i d f r o m P R O J W B S W H E R E p a r e n t _ w b s _ i d I S N U L L

Page 13: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

13/27shafferassoc.net/Programmer's Guide.htm

To create an EPS node with a wbs_short_name of ‘Maintenance Projects’ under the root EPS use the create_eps() stored procedure:

C A L L c r e a t e _ e p s ( 4 3 6 , ‘ M a i n t e n a n c e P r o j e c t s ’ )

The wbs_id for the newly created entry is an autogenerated field and can be obtained from SYSTABLES by querying the last_assigned_key field:

S E L E C T l a s t _ a s s i g n e d _ k e y F R O M S Y S T A B L E S W H E R E a p i _ t a b l e _ n a m e = ‘ P R O J W B S ’

Note: If another EPS node exists with the same wbs_short_name, a numerical value is appended

and stored as ‘Maintenance Projects-1’.

Creating a Project (return to Table of Contents)The sample code below creates a Project with proj_short_name as ‘System Integration’. The proj_short_name is stored as a unique value for eachentry in the PROJECT table. Project level data can be modified with a default scope_level. The create_project() stored procedure also requires a wbs_id of a valid EPS node. The new project is created under the specified EPS node. In the following example, 23454 is a valid EPS node with wbs_id = 23454.

C A L L c r e a t e _ p r o j e c t ( 2 3 4 5 4 , ' S y s t e m I n t e g r a t i o n ' )

Note: If another project exists with the same proj_short_name, a numerical value is appended

and stored as ‘System Integeration-1’. To modify the default values, select the project using the following query. The proj_id can also be determined using the last_assigned_key fromSYSTABLES.

S E L E C T l a s t _ a s s i g n e d _ k e y F R O M S Y S T A B L E S W H E R E a p i _ t a b l e _ n a m e = ‘ P R O J E C T ’S E L E C T p r o j _ i d F R O M P R O J E C T W H E R E p r o j _ s h o r t _ n a m e = ' S y s t e m I n t e g r a t i o n 'U P D A T E P R O J E C T s e t p r o j _ s h o r t _ n a m e = ' S a m p l e P r o j e c t ' W H E R E p r o j _ i d = 3 5 6 4 ;

Note: Every project also has a corresponding entry in the PROJWBS table. Creating a WBS node (return to Table of Contents)A WBS node can be inserted directly in the PROJWBS table. However, a WBS node must be associated with a project. The example below assumes thata project called ‘System Integration’ with proj_id = 3564 exists in the database. Note that the appropriate scope_level is required to insert a WBS node.

I N S E R T I N T O P R O J W B S ( w b s _ i d , p r o j _ i d ) V A L U E S ( 0 , 3 5 6 4 )

A WBS node associated with ‘System Integration’ is created above. SYSTABLES can then be queried to determine the wbs_id for the new entry asfollows:

S E L E C T l a s t _ a s s i g n e d _ k e y F R O M S Y S T A B L E S W H E R E a p i _ t a b l e _ n a m e = ‘ P R O J W B S ’

( a s s u m e r e t u r n v a l u e o f 3 4 8 3 2 ) U P D A T E P R O J W B S s e t w b s _ n a m e = ‘ I T S y s t e m s ’ W H E R E w b s _ i d = 3 4 8 3 2

The update statement above modifies the wbs_name to ‘IT Systems’. Multiple WBS nodes can be associated with the same project.

Creating a Task (return to Table of Contents)To add tasks to the TASK table associate them with a WBS node. Select the appropriate WBS node from the PROJWBS table as described below. U P D A T E P R O J E C T S E T s c o p e _ l e v e l = 7 W H E R E p r o j _ i d = 3 5 6 4

S E L E C T w b s _ i d F R O M P R O J W B S W H E R E p r o j _ i d = 3 5 6 4 A N D w b s _ s h o r t _ n a m e = ‘ I T S y s t e m s ’

The new task is added to ‘System Integration’ under the WBS node called IT Systems with a wbs_id = 4893. Since the wbs_short_name is uniquewithin each project, the above query returns a unique value. Once the location of the task has been established by either selecting an existing WBS nodeor creating a new WBS node, the new task can be inserted in the TASK table. To access the data stored in the TASK table, the appropriate scope levelneeds to be set for the project as described.

U P D A T E P R O J E C T s e t s c o p e _ l e v e l = 7 W H E R E p r o j _ i d = 3 5 6 4I N S E R T I N T O T A S K ( t a s k _ i d , w b s _ i d ) V A L U E S ( 0 , 4 8 9 3 ) S E L E C T l a s t _ a s s i g n e d _ k e y F R O M S Y S T A B L E S W H E R E a p i _ t a b l e _ n a m e = ‘ T A S K ’

( a s s u m e r e t u r n v a l u e o f 3 3 6 8 2 )

Page 14: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

14/27shafferassoc.net/Programmer's Guide.htm

U P D A T E T A S K S E T t a s k _ n a m e = ‘ I n s t a l l U p g r a d e s ’ W H E R E t a s k _ i d = 3 3 6 8 2

Once the task has been created, the task_id can be obtained from the SYSTABLES using the last_assigned_key value as described in the examplesabove. Creating a Resource (return to Table of Contents)To create a resource, add a new record to the RSRC table as follows. No parameters are required to insert the record in the RSRC table.

I N S E R T I N T O R S R C ( r s r c _ i d ) V A L U E S ( 0 ) S E L E C T l a s t _ a s s i g n e d _ k e y F R O M S Y S T A B L E S W H E R E a p i _ t a b l e _ n a m e = ‘ R S R C ’

( a s s u m e r e t u r n v a l u e o f 2 3 4 8 ) U P D A T E R S R C S E T r s r c _ n a m e = ‘ B o b S m i t h ’ W H E R E r s r c _ i d = ‘ 2 3 4 8 ’

Creating a Resource Assignment (return to Table of Contents)To create a resource assignment, add a record to the TASKRSRC table. A resource must be associated with an existing task and the scope_levelrequired to create resource assignments must be set to 7. The sample SQL query below inserts a record in the TASKRSRC table and associates aresource with rsrc_id = 8695 and an activity with task_id = 75447. The newly created taskrsrc_id can be obtained from SYSTABLES using thelast_assigned_key.

I N S E R T I N T O T A S K R S R C ( t a s k _ i d , r s r c _ i d ) V A L U E S ( 7 5 4 4 7 , 8 6 9 5 )S E L E C T l a s t _ a s s i g n e d _ k e y F R O M S Y S T A B L E S W H E R E a p i _ t a b l e _ n a m e = ‘ T A S K R S R C ’

Creating Task Dependencies (return to Table of Contents)The SQL statements below assign a dependency Finish-to-Start between two tasks with task_id =75447 and 76474. The task with task_id =75447 isthe predecessor task. To assign a relationship between these tasks, add a record to the TASKPRED table. The fields required to insert a record inTASKPRED table are task_id, pred_type. The pred_type should be one of the following values:

‘PR_FS’ - Finish to Start‘PR_SF‘ - Start to Finish‘PR_SS’ - Start to Start‘PR_FF’ - Finish to Finish

I N S E R T I N T O T A S K P R E D ( t a s k _ i d , p r e d _ t a s k _ i d , p r e d _ t y p e ) V A L U E S ( 7 5 4 4 7 , 7 6 4 7 4 , ' P R _ F S ' )

Creating a Calendar (return to Table of Contents)Add a record to the CALENDAR table to create a new calendar. Calendars can be one of the following three types:

‘CA_Base’ - Global Calendar‘CA_Rsrc’ - Resource Calendar‘CA_Project’ - Project Calendar

To add a Global Calendar, the calendar type and an associated project must be specified when a record is inserted. The following code creates a GlobalCalendar and then finds the id of the created calendar.

I N S E R T I N T O C A L E N D A R ( c l n d r _ t y p e ) v a l u e s ( ' C A _ B a s e ' )S E L E C T l a s t _ a s s i g n e d _ k e y F R O M S Y S T A B L E S W H E R E a p i _ t a b l e _ n a m e = ' C A L E N D A R '

( a s s u m e r e t u r n v a l u e o f 2 3 4 5 )

The calendar name can be updated to ‘Development Calendar’ for a clndr_id = 2345 that is obtained from SYSTABLES as follows:

U P D A T E C A L E N D A R S E T c l n d r _ n a m e = ' D e v e l o p m e n t C a l e n d a r ' W H E R E c l n d r _ i d = 2 3 4 5

Resource and project calendars can also be created using the specified clndr_type. Each Project and Resource Calendar can inherit the properties ofthe Global Calendar. Update the base_clndr_id field with the preferred base calendar to reflect any changes as shown below.

I N S E R T I N T O C A L E N D A R ( c l n d r _ t y p e , p r o j _ i d ) V A L U E S ( ' C A _ P r o j e c t ' , 3 5 6 4 )S E L E C T l a s t _ a s s i g n e d _ k e y F R O M S Y S T A B L E S W H E R E a p i _ t a b l e _ n a m e = ' C A L E N D A R '

( a s s u m e a r e t u r n v a l u e o f 2 5 7 8 )

Page 15: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

15/27shafferassoc.net/Programmer's Guide.htm

U P D A T E C A L E N D A R S E T b a s e _ c l n d r _ i d = 2 3 4 5 W H E R E c l n d r _ i d = 2 5 7 8

Similarly, a Resource Calendar can be created as described below. Once the calendar is created, obtain the clndr_id from SYSTABLES and update thefields as required.

I N S E R T I N T O C A L E N D A R ( c l n d r _ t y p e ) V A L U E S ( ' C A _ R s r c ' )

Creating an Activity Code (return to Table of Contents)When dealing with activity codes, you need to consider Activity Code Types and Activity Code Values. Each Activity Code Type may have several valuesassociated with it. For example, a code for Project Phase may have the values Requirements and Design. The table ACTVTYPE contains the activity code.

S E L E C T a c t v _ c o d e _ t y p e _ i d , p r o j _ i d , a c t v _ s h o r t _ l e n , a c t v _ c o d e _ t y p e F R O M A C T V T Y P E

actv_code_type_id proj_id actv_short_len actv_code_type75 7 Location Code76 307 7 Sub Contractor

Codes can be either global or project specific. For example, the ‘Location’ code entry above is global and the ‘Sub Contractor’ code entry above isspecific to proj_id 307. The following queries can be used to create a project-level activity code:

I N S E R T I N T O A C T V T Y P E ( a c t v _ c o d e _ t y p e _ i d , p r o j _ i d ) V A L U E S ( 0 , 3 5 6 4 )

A global activity code is created if an association to proj_id is removed. The actv_type_id can then be obtained from SYSTABLES. The table ACTVCODE contains the possible values for a given activity code. S E L E C T a c t v _ c o d e _ i d , a c t v _ c o d e _ t y p e _ i d , s h o r t _ n a m e , a c t v _ c o d e _ n a m e F R O M A C T V C O D E W H E R E a c t v _ c o d e _ t y p e _ i d = 7 5

actv_code_id actv_code_type_id short_name actv_code_name1200 75 ATLC Atlanta corporate center1201 75 SLCE Salt Lake City engineering1202 75 RTC Roanoke test center1203 75 BDC Birmingham development The table above shows the following valid code values for Location Code are ‘Atlanta corporate center’, ‘Salt Lake City engineering’, ‘Roanoke testcenter’, and ‘Birmingham development’. Activity code values can be assigned to an activity code by adding records to the ACTVCODE table as shownbelow. The value for actv_code_type_id is assumed to be 234.

I N S E R T I N T O A C T V C O D E ( a c t v _ c o d e _ i d , a c t v _ c o d e _ t y p e _ i d ) v a l u e s ( 0 , 2 3 4 )

The table TASKACTV contains the assignments of activity code values to tasks, as shown in the following query.

S E L E C T t a s k _ i d , a c t v _ c o d e _ t y p e _ i d , a c t v _ c o d e _ i d , p r o j _ i d F R O M T A S K A C T V

task_id actv_code_type_id actv_code_id proj_id32568 75 1202 30732569 75 1202 30732570 75 1202 30732571 75 1200 30732572 75 1200 307

An activity code value can be assigned to a task by inserting the value in the TASKACTV table. The task_id = 75447 and actv_code_id = 1200 andactv_code_type_id = 75.

I N S E R T I N T O T A S K A C T V ( t a s k _ i d , a c t v _ c o d e _ i d , a c t v _ c o d e _ t y p e _ i d ) V A L U E S ( 7 5 4 4 7 , 1 2 0 0 , 7 5 )

Creating a User (return to Table of Contents)When creating new users, you must consider account users and user rights. The USERS table contains a listing of all users in the system. These areglobal data, so they require scope level 1. To display a list of users in the system:

S E L E C T u s e r _ i d , u s e r _ n a m e F R O M U S E R S

To add a user:

Page 16: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

16/27shafferassoc.net/Programmer's Guide.htm

I N S E R T I N T O U S E R S ( u s e r _ i d , p r o f _ i d , a c t u a l _ n a m e ) V A L U E S ( 0 , 1 2 , ’ B o b S m i t h ’ )S E L E C T l a s t _ a s s i g n e d _ k e y F R O M S Y S T A B L E S W H E R E a p i _ t a b l e _ n a m e = ' U S E R S '

( a s s u m e a r e t u r n v a l u e o f 2 5 )

To edit an existing user:

U P D A T E U S E R S S E T u s e r _ n a m e = ' B o b ' W H E R E u s e r _ i d = 2 5

To delete a user:

D E L E T E F R O M U S E R S W H E R E u s e r _ n a m e = ' B o b '

Each user has a security privilege identified by the prof_id, which links the USERS table to the PROFILE table.When creating new users in using the Primavera SDK, you can update the security profile of each inserted user.A user must have a security profile.

S E L E C T u s e r _ i d , p r o f _ i d , u s e r _ n a m e F R O M U S E R S W H E R E u s e r _ n a m e = ' a d m i n '

user_id prof_id user_name25 12 admin

This above select returns a prof_id of 12.

S E L E C T p r o f _ i d , p r o f _ n a m e F R O M P R O F I L E W H E R E p r o f _ i d = 1 2

prof_id prof_name12 <Admin Superuser>

Activating Baselines for Loaded Project (return to Table of Contents)When an SDK session begins, all projects’ baseline fields reflect the current plan. The user’s preferences are not used to activate any project baselinesas in the GUI – this is the programmer’s responsibility.

To activate a baseline, first locate the desired baseline row in the PROJBASE table. Then, issue an update statement to activate that baseline. Notethat the associated project should be loaded with scope_level=7 already.

��������U P D A T E P R O J B A S E S E T c u r r e n t _ b a s e l i n e _ f l a g = ‘ Y ’ W H E R E p r o j _ i d = 1 2 3

MS Access Example (return to Table of Contents) 1)������������������In MS Access, go to File, New Database… and create a Blank Database2)������������������Go to File, Get External Data >, Link Tables…3)������������������Under ‘Files of type’ set to ‘ODBC Databases()’4)������������������Click the ‘Machine Data Source’ tab and select your Primavera SDK data source5)������������������If prompted to Login, login as a super-user (i.e., Admin/Admin):

6)������������������Select desired tables to link to:

Page 17: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

17/27shafferassoc.net/Programmer's Guide.htm

Note: In MS Access, you can link to a table even if you do not set the scope level accordingly. This will result in tables not displaying accurate

information until the scope level is set to a correct level. To set the scope_level in Access you need to create an Update Query. The following isan example of an Update Query in Access that will set the scope_level for all projects to ‘7’ (SCOPE_LEVEL_ALL):

Note: When linking to any of the spread tables (see SpreadTables&Fields.htm) in MS Access, you will be prompted to ensure data integrity

by choosing fields that uniquely identify each record. For each of the spread tables you will select the first four fields. For example, when linking to the spread table TASKRSRC_SPREADS you will need to select the fields:taskrsrc_id, spread_type, start_date and normal format to allow MS Access to uniquely identify eachrecord in the table.

Visual Basic/ADO Example (return to Table of Contents) ActiveX Data Objects (ADO) (return to Table of Contents)Open Database Connectivity (ODBC) is a widely accepted Application Programming Interface (API) for database access. It is based on the Call-Level

Page 18: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

18/27shafferassoc.net/Programmer's Guide.htm

Interface (CLI) specifications from X/Open and ISO/IEC for database APIs and uses Structured Query Language (SQL) as its database accesslanguage. OLEDB is Microsoft's strategic low-level interface to data across the organization. OLEDB is an open specification designed to build on the success ofODBC by providing an open standard for accessing all kinds of data. ADO is designed as an easy-to-use application level interface to Microsoft's newest and most powerful data access paradigm, OLEDB. OLEDBprovides "high-performance" access to any data source, including relational and non-relational databases, e-mail and file systems, text and graphics,custom business objects, and more. ADO is implemented with a small footprint, minimal network traffic in key Internet scenarios, and a minimalnumber of layers between the front-end and data source, to provide a lightweight, high-performance interface. ADO is easy to use because it is calledusing a familiar metaphor, the OLE Automation interface, available from just about any tool and language on the market today. And since ADO wasdesigned to combine the best features of, and eventually replace RDO and DAO, it uses similar conventions with simplified semantics to make it easyto learn for today's developers. ADO is advantageous since it has a very simple programming model. Below is a diagram showing the objects and how they relate to one another:

Summary of ADO Model: The Connection ObjectThe Connection object represents a connection to the data source and allows you to execute commands. To execute any kind of command, you use theExecute method of the Connection object. If the command returns rows, a default Recordset object is created and returned. To specify a more complexRecordset, you create a new Recordset object, associate it with the Connection, and open the cursor. The Command ObjectThe Command object represents a command (also known as a query or statement) that can be processed by the data source. Commands can returnrows or not, and if the provider is capable, can also handle parameters. The Command object is actually optional in the ADO model because some dataproviders cannot supply command execution, but the object is supported if the provider supports commands. Commands can be simple SQL statements (or some other language the data provider recognizes) or calls to stored procedures in the database.Commands can then be executed using the Command's Execute method, or you can create a Recordset object and associate it with the Commandobject when opening the cursor. The Command object includes a collection of Parameter objects, which is described below. If the provider can support commands with parameters, theParameters collection will contain one parameter object for each parameter in the command. As opposed to past models, you can create Parameterobjects and explicitly add them to the Parameters collection, thus allowing you to use well-known parameterized commands to avoid the sometimesvery expensive operation of having the provider populate the Parameters collection automatically based on the system catalog. The Parameter ObjectThe Parameter object represents a parameter of a Command. As noted in the Command description, you can explicitly create Parameter objects andadd them to the Parameters collection to avoid the often unnecessary and expensive task of going to the system catalog to automatically populate theparameter binding information. The Recordset ObjectThe Recordset object is by far the most complex (the others are simplified considerably). This is not surprising, however, because all the cursorfunctionality is represented in this object. The Recordset object looks much like it does in existing models today, but a number of improvements havebeen made, such as removing unnecessary elements, adding optional arguments that reduce the number of lines of code for common scenarios, andchanging defaults that didn't make sense in today's technologies. The Field ObjectThe Field interface represents a column in a Recordset that you can use to obtain values, modify values, and learn about column meta-data. This objectis almost identical to past models, but includes some new functionality.

Page 19: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

19/27shafferassoc.net/Programmer's Guide.htm

The Error ObjectThe Error object represents an error returned from a data source. This object is actually optional because it is only needed when data sources canreturn multiple errors for a single method call. If a provider does not return multiple errors for a single function call, the provider just raises the errorthrough the normal COM mechanisms that all COM servers do when called from languages like Visual Basic.��Sample Visual Basic/ADO code: In Visual Basic, start a new project. In order to use ADO, you need to add a reference to‘Mocrosoft ActiveX Data Objects Library. In your VB project go to ‘Project, References…’and select the ADO library.

S u b M a i n ( )

D i m S D K A s A D O D B . C o n n e c t i o n

D i m R e c S e t A s A D O D B . R e c o r d S e t

D i m l N u m R e c o r d s A s L o n g

‘ 1 ) c r e a t e A D O c o n n e c t i o n o b j e c t

S e t S D K = N e w A D O D B . C o n n e c t i o n

‘ 2 ) e s t a b l i s h c o n n e c t i o n

C a l l S D K . O p e n ( < S y s t e m D a t a S o u r c e N a m e > , < u s e r n a m e > , < p a s s w o r d > )

‘ 3 ) o b t a i n a r e c o r d s e t o f t h e c o n t e n t s o f t h e P R O J E C T t a b l e

‘ w h e r e l N u m R e c o r d s w i l l r e t u r n t h e n u m b e r o f r e c o r d s f o u n d

‘ a n d a d C m d U n k n o w n i s a n A D O c o n s t a n t t h a t s p e c i f i e s t h a t y o u a r e n o t

‘ s p e c i f i c a l l y i d e n t i f y i n g t h e c o m m a n d y o u a r e

‘ a b o u t t o e x e c u t e

S e t R e c S e t = S D K . E x e c u t e ( “ S E L E C T * F R O M P R O J E C T ” , l N u m R e c o r d s , a d C m d U n k n o w n )

‘ 4 ) d i s p l a y t h e c o n t e n t s p r o j _ i d f i e l d v a l u e o f e a c h r e c o r d

R e c S e t . M o v e F i r s t

W h i l e N o t ( R e c S e t . E O F )

M s g B o x R e c S e t . F i e l d s ( “ P R O J _ I D ” ) . V a l u e

R e c S e t . M o v e N e x t

W e n d

‘ 5 ) c l o s e / d e s t r o y t h e r e c o r d s e t

R e c S e t . C l o s e

S e t R e c S e t = N o t h i n g

‘ 6 ) c l o s e / d e s t r o y t h e c o n n e c t i o n

S D K . C l o s e

S e t S D K = N o t h i n g

E n d S u b

Lotus Notes Example (return to Table of Contents) Here is a quick Lotus Notes demo on how to establish a connectionto a System DSN that can be used with the Primavera SDK:

Page 20: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

20/27shafferassoc.net/Programmer's Guide.htm

1)������������������In Notes, if you create a new empty database, expand the Design section, and double-click on Database Script...�

2)������������������In the (Options) event add the following include statement:

3) Then, switch to the Postopen event and add the following code:�

4) Save and close the database. 5) Reopen the database and the following dialog will appear:

7)������������������Enter the name of your SDK System DSN and it will let you know if it was able

to successfully establish a connection.

Page 21: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

21/27shafferassoc.net/Programmer's Guide.htm

8)������������������Once you have a connection object established you are off and running, executing SQL queries,

creating result sets, etc.

Microsoft Windows Scripting Host (WSH)/ADO Example (return to Table of Contents)

Microsoft® Windows® Script Host (WSH) is a language-independent scripting host for ActiveX® scripting engines. It brings simple, powerful, andflexible scripting to the Windows 32-bit platform, allowing you to run scripts from both the Windows desktop and the command prompt. Windows Script Host is ideal for non-interactive scripting needs such as logon scripting, administrative scripting, and machine automation.�

Windows Script Host offers the following benefits:x���������Two separate executable files, WScript.exe and CScript.exe, for running scripts either from Windows or from the command prompt.

WScript.exe provides a Windows-based properties page for setting script properties, while CScript.exe provides command-line switches forsetting script properties.

x���������Support for multiple files. You can call multiple scripting engines and perform multiple jobs from a single Windows Script (.wsf) file.x���������Very low memory requirements.x���������Mapping of script extensions to programmatic identifiers (ProgIDs). When you start a script from the Windows desktop or the command prompt,

the script host reads and passes the specified script file contents to the registered script engine. Instead of using the HTML SCRIPT tag to

identify the script, the host uses file extensions; for example, .vbs for Microsoft Visual Basic® Scripting Edition (VBScript) files, and .js for

Microsoft JScript® files. The use of extensions means you no longer need to be familiar with the ProgID for a given script engine. WindowsScript Host handles this for you by maintaining a mapping of script extensions to ProgIDs, launching the appropriate engine for a given script.

Windows Script Host is integrated into Windows 98, Windows 2000 Professional, and Windows 2000 Server. Version 2.0 includes the VBScript andJScript scripting engines. In the future, other software companies may provide ActiveX scripting engines for languages such as PerlScript, TCL, REXX,and Python.

Sample WSH JScript/ADO code: The following sample JScript code displays the current number of projects found in aPrimavera SDK data source connection: < p a c k a g e >

< J o b i d = " g e t P r o j e c t C o u n t " >

< S c r i p t l a n g u a g e = " J S c r i p t " >

/ / c r e a t e A D O c o n n e c t i o n o b j e c t . . .

v a r c n = n e w A c t i v e X O b j e c t ( " A D O D B . C o n n e c t i o n " ) ;

/ / o p e n c o n n e c t i o n . . .

c n . O p e n ( < S y s t e m D a t a S o u r c e N a m e > , < u s e r n a m e > , < p a s s w o r d > ) ;

v a r N u m R e c A f f ;

v a r a d C m d U n k n o w n = 8 ; / / a d o c o n s t a n t

/ / e x e c u t e S Q L c o m m a n d …

v a r r s = c n . e x e c u t e ( " S E L E C T C O U N T ( * ) F R O M P R O J W B S W H E R E N O D E _ T Y P E = ' P R O J E C T ' " , N u m R e c A f f , a d C m d U n k n o w n ) ;

W S c r i p t . e c h o ( " P r o j e c t C o u n t : " + r s . F i e l d s . I t e m ( 0 ) . V a l u e ) ;

r s . C l o s e ( ) ;

r s = n u l l ;

c n . C l o s e ( ) ;

c n = n u l l ;

< / S c r i p t >

< / J o b >

< / p a c k a g e >

[ Save the code above into a file called ‘getProjectCount.wsf’ ] Double-click on the ‘getProjectCount.wsf’ file to get the output: OR from the command line, enter the following:

> c s c r i p t / / j o b : g e t P r o j e c t C o u n t g e t P r o j e c t C o u n t . w s f

M i c r o s o f t ( R ) W i n d o w s S c r i p t H o s t V e r s i o n 5 . 1 f o r W i n d o w s

C o p y r i g h t ( C ) M i c r o s o f t C o r p o r a t i o n 1 9 9 6 - 1 9 9 9 . A l l r i g h t s r e s e r v e d .

P r o j e c t C o u n t : 2 6

Page 22: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

22/27shafferassoc.net/Programmer's Guide.htm

OR from the command line, enter the following:

> w s c r i p t / / j o b : g e t P r o j e c t C o u n t g e t P r o j e c t C o u n t . w s f

Java Example (using JDBC-ODBC) (return to Table of Contents) i m p o r t j a v a . s q l . * ;

c l a s s s d k _ j d b c _ o d b c

{

p u b l i c s t a t i c v o i d m a i n ( S t r i n g [ ] a r g s )

{

S t r i n g u r l = " j d b c : o d b c : < D a t a S o u r c e > " ;

S t r i n g q u e r y = " S E L E C T P R O J _ I D F R O M P R O J E C T " ;

t r y

{

/ / l o a d t h e j d b c - o d b c b r i d g e d r i v e r …

C l a s s . f o r N a m e ( " s u n . j d b c . o d b c . J d b c O d b c D r i v e r " ) ;

/ / e s t a b l i s h c o n n e c t i o n …

C o n n e c t i o n c o n = D r i v e r M a n a g e r . g e t C o n n e c t i o n ( u r l , " < u s e r N a m e > " , " < p a s s w o r d > " ) ;

/ / c r e a t e a s t a t e m e n t o b j e c t s o w e c a n s u b m i t S Q L s t a t e m e n t s t o t h e d r i v e r

S t a t e m e n t s t m t = c o n . c r e a t e S t a t e m e n t ( ) ;

R e s u l t S e t r s = s t m t . e x e c u t e Q u e r y ( q u e r y ) ;

p r i n t R e s u l t S e t ( r s ) ;

r s . c l o s e ( ) ;

s t m t . c l o s e ( ) ;

c o n . c l o s e ( ) ;

}

c a t c h ( S Q L E x c e p t i o n e x )

{

w h i l e ( e x ! = n u l l )

{

S y s t e m . o u t . p r i n t l n ( " S Q L E x c e p t i o n : " + e x . g e t M e s s a g e ( ) ) ;

e x = e x . g e t N e x t E x c e p t i o n ( ) ;

}

}

c a t c h ( j a v a . l a n g . E x c e p t i o n e x )

{

e x . p r i n t S t a c k T r a c e ( ) ;

}

}

p r i v a t e s t a t i c v o i d p r i n t R e s u l t S e t ( R e s u l t S e t r s ) t h r o w s S Q L E x c e p t i o n

{

i n t n u m C o l s = r s . g e t M e t a D a t a ( ) . g e t C o l u m n C o u n t ( ) ;

w h i l e ( r s . n e x t ( ) )

{

f o r ( i n t i = 1 ; i < = n u m C o l s ; i + + )

{

i f ( i = = n u m C o l s )

S y s t e m . o u t . p r i n t ( r s . g e t S t r i n g ( i ) ) ;

e l s e

S y s t e m . o u t . p r i n t ( r s . g e t S t r i n g ( i ) + " , " ) ;

}

S y s t e m . o u t . p r i n t l n ( ) ;

}

}

}

[ Save code above to a file called ‘sdk_jdbc_odbc.java’. ] From the command line, enter the following to compile the .java file: > j a v a c s d k _ j d b c _ o d b c . j a v a

From the command line, enter the following to execute the .class file: > j a v a s d k _ j d b c _ o d b c

Primavera SDK Log File(s) (return to Table of Contents)

The Primavera SDK automatically generates a log file in the TEMP folder called ‘PrmSDK.log’.

Page 23: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

23/27shafferassoc.net/Programmer's Guide.htm

To determine the TEMP folder type ‘set’ at a command prompt: Example:

> s e t …

T E M P = C : \ T E M P ( f o r W i n N T )O R

T E M P = C : \ W I N D O W S \ T E M P ( f o r W i n 9 5 / 9 8 ) …

The Primavera SDK logs actions/methods that are performed by the application (VDB) to service a request. The log also provides the success/failure ofthe actions/methods performed, as well as any errors that may have taken place in processing a request. Note: You can control the level of detail that is written to the log file using the ‘Options for logging messages’ setting found in the

‘Primavera Software Development Kit Setup’ dialog. The setting can be set to terse, verbose, or none. Sample terse (less detail) output (establishing a connection):

0 1 0 3 1 3 : 1 8 : 4 1 : 5 6 . 3 6 1 - V D B . C o n n e c t :

d a = P M S D K _ P E ; D r i v e r = P r i m a v e r a P M S D K ; e n g i n e = P 3 e ; l f = C : \ t e m p \ P M S D K . L O G ; l o = t e r s e ; p g = 1 ; p p = p u b u s e r ; p u = p u b u s e r ; a s

" a d m i n " s u c c e s s f u l

Sample verbose (more detail) output (establishing a connection):0 1 0 3 1 3 : 1 8 : 4 4 : 5 2 . 8 6 5 - V D B . C o n n e c t : " a d m i n " u s i n g

p a r a m s = d a = P M S D K _ P E ; D r i v e r = P r i m a v e r a P M S D K ; e n g i n e = P 3 e ; l f = C : \ t e m p \ P M S D K . L O G ; l o = v e r b o s e ; p g = 1 ; p p = p u b u s e r ; p u = p u b u s e r ;

0 1 0 3 1 3 : 1 8 : 4 4 : 5 4 . 7 3 7 - U S E S S I O N - G E T N E W K E Y

0 1 0 3 1 3 : 1 8 : 4 4 : 5 4 . 8 0 8 - S E L E C T * f r o m u s e r s W H E R E u s e r _ i d = 2 5

0 1 0 3 1 3 : 1 8 : 4 4 : 5 4 . 8 1 8 - S E L E C T * f r o m p r o f i l e W H E R E p r o f _ i d = 1 2

0 1 0 3 1 3 : 1 8 : 4 4 : 5 4 . 8 2 8 -

0 1 0 3 1 3 : 1 8 : 4 4 : 5 4 . 8 2 8 - R E F R E S H I N G - A l l T a b l e s

0 1 0 3 1 3 : 1 8 : 4 4 : 5 4 . 8 2 8 - R E F R E S H I N G - P R E F E R

0 1 0 3 1 3 : 1 8 : 4 4 : 5 4 . 8 2 8 - S Q L - S E L E C T * F R O M p r e f e r O R D E R B Y p r e f e r _ i d

e t c .

Sample verbose output (establishing a connection with an invalid password):

0 1 0 3 1 3 : 1 8 : 4 7 : 4 9 . 2 7 8 - V D B . C o n n e c t : " a d m i n " u s i n g

p a r a m s = d a = P M S D K _ P E ; D r i v e r = P r i m a v e r a P M S D K ; e n g i n e = P 3 e ; l f = C : \ t e m p \ P M S D K . L O G ; l o = v e r b o s e ; p g = 1 ; p p = p u b u s e r ; p u = p u b u s e r ;

0 1 0 3 1 3 : 1 8 : 4 7 : 5 0 . 7 7 1 - L o g o n f a i l e d : i n v a l i d p a s s w o r d

0 1 0 3 1 3 : 1 8 : 4 7 : 5 0 . 7 7 1 - E R R O R = > L o g o n f a i l e d : i n v a l i d p a s s w o r d

V D B . C o n n e c t ; h R e s u l t = 0 x 8 0 0 4 0 0 1 1 ( P M S D K _ E _ B A D _ L O G O N : u s e r n a m e / p a s s w o r d o r l i c e n s e i n v a l i d ) ; E O l e S y s E r r o r = S D K

f a i l e d t o l o g o n t o d r i v e r

0 1 0 3 1 3 : 1 8 : 4 7 : 5 0 . 7 9 1 - V D B . D i s c o n n e c t

SQL (aggregate/scalar) functions supported by the Primavera SDK/OA(return to Table of Contents) Aggregate functions supported <se t - f u n c t i o n - s p e c > : : = C O U N T ( * ) | A V G ( [ A L L | D I S T I N C T ] < v a l u e - e x p r e s s i o n > ) | M I N ( [ A L L | D I S T I N C T ] < v a l u e - e x p r e s s i o n > ) | M A X ( [ A L L | D I S T I N C T ] < v a l u e - e x p r e s s i o n > ) | S U M ( [ A L L | D I S T I N C T ] < v a l u e - e x p r e s s i o n > ) | C O U N T ( [ A L L | D I S T I N C T ] < v a l u e - e x p r e s s i o n > )

Examples: S E L E C T A V G ( c o s t _ p e r _ q t y ) F R O M R S R C S E L E C T M I N ( c o s t _ p e r _ q t y ) F R O M R S R C S E L E C T M A X ( c o s t _ p e r _ q t y ) F R O M R S R C S E L E C T S U M ( c o s t _ p e r _ q t y ) F R O M R S R C S E L E C T C O U N T ( * ) F R O M R S R C

Page 24: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

24/27shafferassoc.net/Programmer's Guide.htm

Scalar functions supported: Summary:Category: Functions:

String ascii, char, concat, lcase, lower, left, length, locate, ltrim, repeat, rtrim, ucase, upper

Date/time curdate, curtime, dayname, dayofmonth, hour, minute, month, monthname, now, second, year

Numeric mod

System user, database �

Detail:Function/Syntax: Description: Sample SQL: Sample Output:

String

A SC II(string_exp) Returns the A SC II code v alue of the leftmost character

of string_exp as an integer.

select rsrc_name from rsrc where

ascii(rsrc_name)=67

rsrc_name

C apital Projects

C onstruction Department

C ustomer Relations

C HA R(code) Returns the character that has the A SC II code v alue

specified by code. The v alue of code should be between

0 and 255; otherw ise, the return v alue is data source–

dependent.

select char(65),rsrc_name from rsrc C ol1 rsrc_name

A C apital Projects

A C onstruction Department

A O perating Engineer

C O NC A T(string_exp1,

string_exp2)

Returns a character string that is the result of

concatenating string_exp2 to string_exp1. The resulting

string is DBMS-dependent. For example, if the column

represented by string_exp1 contained a NULL v alue, DB2

would return NULL but SQ L Serv er would return the

non-NULL string.

select concat(rsrc_id,rsrc_name) from rsrc C ol1

1C apital Projects

1159C onstruction Department

1160O perating Engineer

LC A SE(string_exp)

LO WER(string_exp)

Returns a string equal to that in string_exp, w ith all

uppercase characters conv erted to lowercase.

select lcase(rsrc_name) from rsrc

select lower(rsrc_name) from rsrc

C ol1

capital projects

construction department

operating engineer

LEFT(string_exp, count) Returns the leftmost count characters of string_exp. select left(rsrc_name,2) from rsrc C ol1

C a

C o

O p

LENGTH(string_exp) Returns the number of characters in string_exp, excluding

trailing blanks.

select length(rsrc_name) from rsrc C ol1

16

23

18

LO C A TE(string_exp1,

string_exp2[, start])

Returns the starting position of the first occurrence of

string_exp1 w ithin string_exp2. The search for the first

occurrence of string_exp1 begins w ith the first character

position in string_exp2 unless the optional argument, start,

is specified. If start is specified, the search begins w ith

the character position indicated by the v alue of start. The

first character position in string_exp2 is indicated by the

v alue 1. If string_exp1 is not found w ithin string_exp2,

the v alue 0 is returned.

select locate('a',rsrc_name,1) from rsrc C ol1

2

17

5

LTRIM(string_exp) Returns the characters of sring_exp, w ith leading blanks

remov ed.

REPEA T(string_exp, count) Returns a character string composed of string_exp

repeated count times.

select repeat('x',10) from <table> C ol1

xxxxxxxxxx

xxxxxxxxxx

xxxxxxxxxx

RTRIM(string_exp) Returns the characters of string_exp w ith trailing blanks

remov ed.

UC A SE(string_exp)

UPPER(string_exp)

Returns a string equal to that in string_exp, w ith all

lowercase characters conv erted to uppercase.

select ucase(rsrc_name) from rsrc

select upper(rsrc_name) from rsrc

C ol1

C A PITA L PRO JEC TS

C O NSTRUC TIO N DEPA RTMENT

O PERA TING ENGINEER

Function/Syntax: Description: Sample SQL: Sample Output:

Date/Time � � �

C URDA TE( ) Returns the current date. select concat(rsrc_name,curdate()) from rsrc C ol1

C apital Projects2000-12-12

C onstruction Department2000-12-12

O perating Engineer2000-12-12

Page 25: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

25/27shafferassoc.net/Programmer's Guide.htm

C URTIME( ) Returns the current local time. select concat(rsrc_name,curtime()) from rsrc C ol1

C apital Projects11:15:00

C onstruction Department11:15:00

O perating Engineer11:15:00

DA YNA ME(date_exp) Returns a character string containing the data source–

specific name of the day (for example, Sunday

through Saturday or Sun. through Sat. for a data

source that uses English, or Sonntag through

Samstag for a data source that uses German) for the

day portion of date_exp.

select day name(plan_start_date) from project C ol1

Thursday

F riday

Saturday

F riday

Monday

DA YO FMO NTH(date_exp) Returns the day of the month based on the month

field in date_exp as an integer v alue in the range of

1–31.

select day ofmonth(plan_start_date) from project C ol1

19

2

7

4

HO UR(time_exp)

Returns the hour based on the hour field in time_exp

as an integer v alue in the range of 0–23.

select hour(target_start_date) from task C ol1

8

8

11

10

MINUTE(time_exp)

Returns the minute based on the minute field in

time_exp as an integer v alue in the range of 0–59.

select minute(target_start_date) from task C ol1

0

0

12

MO NTH(date_exp)

Returns the month based on the month field in

date_exp as an integer v alue in the range of 1–12.

select month(target_start_date) from task C ol1

7

9

9

12

MO NTHNA ME(date_exp) Returns a character string containing the data source–

specific name of the month (for example, January

through December or Jan. through Dec. for a data

source that uses English, or Januar through

Dezember for a data source that uses German) for

the month portion of date_exp.

select monthname(target_start_date) from task C ol1

July

A ugust

A ugust

September

NO W( ) Returns current date and time as a timestamp v alue. select concat(rsrc_name,now()) from rsrc C ol1

C apital Projects2000-12-12 11:45:12

C onstruction Department2000-12-12

11:45:12

SEC O ND(time_exp) Returns the second based on the second field in

time_exp as an integer v alue in the range of 0–59.

select second(target_start_date) from task C ol1

0

0

0

YEA R(date_exp) Returns the y ear based on the y ear field in date_exp

as an integer v alue. The range is data source–

dependent.

select y ear(target_start_date) from task C ol1

1999

2000

Function/Syntax: Description: Sample SQL: Sample Output:

Numeric � � �

MO D(integer_exp1, integer_exp2)Returns the remainder (modulus) of integer_exp1 div ided

by integer_exp2.

select mod(task_id,10) from task C ol1

1

2

3

4

Function/Syntax: Description: Sample SQL: Sample Output:

System � � �

DA TA BA SE( ) Returns the name of the database corresponding to

the connection handle. (The name of the database is

also av ailable by calling SQ LGetC onnectO ption w ith

the SQ L_C URRENT_Q UA LIF IER connection

option.)

select database() from <table> C ol1

da=PMSDK;Driv er=

Primav eraPMSDK;

engine=P3e;

lf=C :\temp\PMSDK.LO G;

lo=terse;pg=1;pp=pubuser;

pu=pubuser;

USER( ) Returns the user name in the DBMS. (The user

name is also av ailable by way of SQ LGetInfo by

specify ing the information ty pe:

select user() from <table> C ol1

admin

Page 26: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

26/27shafferassoc.net/Programmer's Guide.htm

SQ L_USER_NA ME.) This can be different than the

login name.

FAQ (return to Table of Contents)

What is the SDK?see Overview section.

What is the Universal Framework?

The Universal Framework exposes the appropriate interfaces and connects to the core VDB logic. Since there will be disparate languages and models between the VDB and UF, anencapsulated interface paradigm is required to handle the different memory layout and allocation strategies used by Object Pascal, C++, etc.

What is the preferred means of accessing data via the SDK?

ADO is the preferred method. see ADO section.

Is there a preferred language for using the SDK?

Any programming language that can use ADO is fair game.

Is there an Object Model for the SDK?

The SDK is essentially used by applying appropriate SQL statements to the exposed tables. The Object Model in the case of the SDK is essentially the logical schema of the exposed

logical tables. The SDK is a layer that resides over the VDB via the Universal framework. The VDB validates business rules for the SDK.

Can more than one DSN (Data Source Name) exist for the SDK?

Yes. You can create as many System DSNs as you like.

How is the user name and password configured?

Through the Project Management product. The username and password are the same as the application user.

If you execute a SQL statement such as 'DELETE FROM TASK WHERE TASK_ID = 33210' what occurs? That record is removed from the TASK table, but are

any other references to that task removed from other tables as well (i.e., TASKRSRC which stores resources assigned to that activity)? Can you explain

how this takes place?

All DELETE statements cascade to outer tables. Outer tables means rows in other tables which are dependent upon the row being deleted will be deleted along with the ‘master’

row. In the case of deleting a TASK row, all associated TASKRSRC rows would be deleted, as well. Additionally, all associated TASKPRED, RSRCHOUR, TASKMEMO, etc. rows would

be deleted. The schema documentation should reflect these relationships among tables.

What files are required for the SDK?

see Files Installed section.

Where can I get the latest version of ADO?

ADO is part of Microsoft's Data Access Components (MDAC). You can download the latest version of MDAC from Microsoft's Data Web site. http://www.microsoft.com/data/

How do I know which version of MDAC I have installed on my computer?

The only way to know the version is to look at the ‘msdadc.dll’ file version.

How do I determine (through code) what version of MDAC is installed on a computer?

1) Using the ProgID "ADODB.Connection", get it's CLSID from the system registry.

e.g. HKEY_CLASSES_ROOT\ADODB.Connection\CLSID

=> {00000514-0000-0010-8000-00AA006D2EA4}

2)�������������������Using the CLSID, get the path under "HKEY_CLASSES_ROOT\CLSID\<CLSID>\InprocServer32" from the system registry.

e.g. HKEY_CLASSES_ROOT\CLSID\{00000514-0000-0010-8000-00AA006D2EA4}\InprocServer32

=> C:\Program Files\Common Files\System\ADO\msado15.dll

3)�������������������Get the internal file version of the DLL.

e.g. C:\Program Files\Common Files\System\ADO\msado15.dll

=> 2.10.4202.1

Troubleshooting (return to Table of Contents)

Installation In order to install the Primavera SDK on WinNT/2000, you need to log in to the PC as an Administrator. If you are not logged in to the PC as an Administrator you will receive the following message:

Page 27: Primavera SDK Programmer's Guide

2/9/12 Primavera SDK Programmer's Guide

27/27shafferassoc.net/Programmer's Guide.htm

Connection 1) Make sure that you are using a System DSN. see ODBC Data Source Admin section.

2)������������������Make sure the Database Alias (BDE) that the System DSN is set to is valid.

Tip: Download the following from http://www.inprise.com/devsupport/bde/utilities.html

Database connection checker (Size 136,482 bytes)http://www.inprise.com/devsupport/bde/files/conect32.zipThis program will allow you to check connections to SQL, ODBC, and Standard databases;also verifies that tables can be opened by BDE32.

3)������������������Make sure you are logging into the SDK as an <Admin Superuser>.4)������������������Make sure you can log into the GUI application (if installed).5)������������������Make sure you can log directly into the physical database:

Oracle - use SQL+MS SQL - use Query AnalyzerInterbase - use BDE Administrator

6)������������������Make sure the appropriate physical database client is installed.7)������������������Make sure the appropriate database client service is running.8)������������������Make sure you can ‘ping’ the database server.

Ping verifies connections to a remote computer or computers. This command is available only if the TCP/IP protocol has been installed.> p i n g < s e r v e r n a m e >

Data Access Most data access issues involve not having the appropriate scope_level and/or access_level set for a project. See the sections on scope level and access level. Performance

Avoid using SQL ‘SELECT * FROM <table>’ statements to improve performance. Use more efficient SQL statements like‘SELECT task_id, task_code FROM TASK’ to improve performance when using the Primavera SDK. When working with very large data sets you may (potentially) improve performance by increasing the ‘CacheMemSize’ setting in theOpenRDA.INI file.

Documentation/URL Sources (return to Table of Contents)

Primavera: http://www.primavera.com/ Primavera SDK installed documentation: ‘\Primavera Common\PMSDK\Doc’ Borland: http://www.inprise.com/ MDAC: http://www.microsoft.com/data/ Microsoft ActiveX Data Objects (ADO): http://www.microsoft.com/data/ado/default.htm Microsoft Windows Scripting Technologies: http://msdn.microsoft.com/scripting/ Java: http://java.sun.com/ MSDN: http://msdn.microsoft.com/default.asp Open Access: http://www.atinet.com/