REQUEST A DEMO

More on Extracting ClearBasic Code

There may be a need to extract all the ClearBasic code for entire project at once.

If the project consists of only a few modules, one would use CBEX tool in interactive mode, select the modules from the list, specify the destinations, and export.

But if a project involves very many modules, this method becomes burdensome – CBEX does not have a ‘select all’ capability.

One way to make one’s life easier is to use a tool developed by Dovetail Software, as explained in this article by Gary Sherman.

Another method is to generate a CBEX directive file and then use CBEX in batch mode to export all the code.

The process of generating the directive file is exactly what is burdensome in CBEX GUI, therefore a different method is needed.

This can be achieved by using SQL statements to produce one directive per module, global or of a form. Then the output needs to be saved into a text file with .cbi extension. The last step is to execute CBEX as a command:

cbex -batch -exp -dir my_project.cbi

 

The following SQL may be used to generate the directives:

 

MS SQL:

 

WITH forms(nums,vers) AS (
   SELECT DISTINCT REPLACE(CAST(w.id AS char),' ',''), w.ver_customer
   FROM table_rc_config rc, table_window_db w, mtm_window_db4_rc_config1 wrc
   WHERE wrc.rc_config2window_db = rc.objid AND wrc.window_db2rc_config = w.objid
     AND w.ver_customer <> ''
     AND rc.name = 'my_resource_config'
)
SELECT DISTINCT '"C:\cbs\' + f.nums + '.cbs" -F ' + f.nums + ' "' + REPLACE(SUBSTRING(b.module_name,(CHARINDEX('BASELINE',b.module_name)+10),@@TEXTSIZE),'''','') + '"'
FROM table_behavior b, forms f
WHERE b.cust_ind = 1
  AND b.module_name like '263,%'
  AND SUBSTRING(SUBSTRING(b.module_name,5,@@TEXTSIZE),1,CHARINDEX(',BASELINE',b.module_name)-5)     = f.nums
  AND REPLACE(SUBSTRING(b.module_name,(CHARINDEX('BASELINE',b.module_name)+10),@@TEXTSIZE),'''','') = f.vers
UNION
SELECT DISTINCT '"C:\global_' + 
REPLACE(REPLACE(b.module_name,'83,0,''',''),''',user','') + 
(CASE user_label WHEN '' THEN '' WHEN NULL THEN '' ELSE '_' + user_label END) +
'.cbs" -G ' + REPLACE(REPLACE(b.module_name,'83,0,''',''),''',user','') + 
(CASE user_label WHEN '' THEN '' WHEN NULL THEN '' ELSE ' -N ' + user_label END)
FROM table_behavior b
WHERE b.cust_ind = 1
  AND b.module_name like '83,0,%'
ORDER BY 1

 

Oracle:

 

WITH forms AS (
   SELECT DISTINCT w.id as nums, w.ver_customer as vers
   FROM table_rc_config rc, table_window_db w, mtm_window_db4_rc_config1 wrc
   WHERE wrc.rc_config2window_db = rc.objid AND wrc.window_db2rc_config = w.objid
     AND w.ver_customer is not null
     AND rc.name = 'my_resource_config'
)
SELECT DISTINCT '"C:\cbs\' || f.nums || '.cbs" -F ' || f.nums || ' "' || REPLACE(SUBSTR(b.module_name,(INSTR(b.module_name,'BASELINE')+10)),'''','') || '"'
FROM table_behavior b, forms f
WHERE b.cust_ind = 1
  AND b.module_name like '263,%'
  AND SUBSTR(SUBSTR(b.module_name,5),1,INSTR(b.module_name,',BASELINE')-5)        = f.nums
  AND REPLACE(SUBSTR(b.module_name,(INSTR(b.module_name,'BASELINE')+10)),'''','') = f.vers
UNION
SELECT DISTINCT '"C:\cbs\global_' ||
REPLACE(REPLACE(b.module_name,'83,0,''',''),''',user','') || 
(CASE user_label WHEN '' THEN '' WHEN NULL THEN '' ELSE '_' || user_label END) ||
'.cbs" -G ' || REPLACE(REPLACE(b.module_name,'83,0,''',''),''',user','') ||
(CASE user_label WHEN '' THEN '' WHEN NULL THEN '' ELSE ' -N ' || user_label END)
FROM table_behavior b
WHERE b.cust_ind = 1
  AND b.module_name like '83,0,%'
ORDER BY 1;

 

The output produced would include one line for each custom form belonging to ‘my_resource_config’ resource configuration, plus one line for each global module.

 

Note: the target folder, “C:\cbs” in this example, must exist for CBEX to work. If it does not exist no code will be exported and no warning message will be provided.