[FMP Standards] Proposals > ExecuteSQL Abstraction

15 views
Skip to first unread message

Matt Petrowsky (Confluence)

unread,
Jan 7, 2016, 1:47:33 PM1/7/16
to fmsta...@googlegroups.com
Matt Petrowsky edited a page
 
Change comment: Updated to latest revision.
page icon
ExecuteSQL Abstraction

...

Code Block
Let ( [ ~sql = "
    	SELECT t1.~field
    	FROM ~table1 t1
    	JOIN ~table2 t2
    	ON t1.~field = t2.~field
    	WHERE ~field LIKE '%~value%'
    	AND ~field=?
    	ORDER BY ~field
	";
	$sqlQuery = Substitute ( ~sql ;
		[ "~table1" ; SQLTableName ( Table1::fieldName ) ];
		[ "~table2" ; SQLTableName ( Table2::fieldName ) ];
		[ "~field" ; SQLFieldName ( Table1::fieldName ) ];
		[ "~value" ; Table::field ]
	);
	$sqlResult = ExecuteSQL ( $sqlQuery ; "" ; "" ;
    	$value;
    	$value[2];
    	$value[$n]
	)
];
	//Substitute ( $sqlQuery ; "	" ; "" ) &¶& // sql preview
	If ( $sqlResult = "?" ;
		Let ( ~debug = False ; //If ( ~debug ; SQLDebugResult ( $sqlResult ) ; False ) );
		$sqlResult
	)
)
View page Icon View page
Add comment Icon Add comment
Like Icon Like
 
Stop watching space
Manage notifications
This message was sent by Atlassian Confluence 5.6.6

Matt Petrowsky (Confluence)

unread,
Jan 7, 2016, 1:50:35 PM1/7/16
to fmsta...@googlegroups.com
Matt Petrowsky edited a page

...

Current proposed snippet which uses Substitution method (similar to printf)

 

Code Block
linenumbers true
Let ( [ ~sql = "
	SELECT t1.~field
	FROM ~table1 t1
	JOIN ~table2 t2
	ON t1.~field = t2.~field
	WHERE ~field LIKE '%~value%'
	AND ~field=?
	ORDER BY ~field";
 
	$sqlQuery = Substitute ( ~sql ;
		[ "~table1" ; SQLTableName ( Table1::fieldName ) ];
		[ "~table2" ; SQLTableName ( Table2::fieldName ) ];
		[ "~field" ; SQLFieldName ( Table1::fieldName ) ];
		[ "~value" ; Table::field ]
	);
 
	$sqlResult = ExecuteSQL ( $sqlQuery ; "" ; "" ;
    	$value;
    	$value[2];
    	$value[$n]
	)
];
	//Substitute ( $sqlQuery ; "	" ; "" ) &¶& // sql preview
	If ( $sqlResult = "?" ;
		Let ( ~debug = False ; If ( ~debug ; SQLDebugResult ( $sqlResult ) ; False ) );
		$sqlResult
	)
)
Reply all
Reply to author
Forward
0 new messages