initial conversion of common_sql.php