<?php

//Requ�te de la classe Vm pour mysql
$aSql['mysql']['getVM_TableInfo'] = "SELECT * FROM vm_table WHERE name = '[sTable]'";

//Requ�te de la classe Vm pour pgsql
$aSql['pgsql']['getVM_TableInfo'] = "SELECT * FROM [sSchema].vm_table WHERE \"TABLE_NAME\" = '[sTable]'";
$aSql['pgsql']['getVM_TableInfoTradFramework'] = "SELECT \"name\", \"id_field\", \"id_field_type\", \"id_field_label\", \"sql_list\", \"form_class\", \"sql_form\", translation_title.\"translation\" as \"TITRE_LISTE\", translation_form.\"translation\" as \"form_title\", \"id_field_sequence\", \"schema_name\", \"sorted_by\", \"sorted_dir\", \"edit_column\" , \"show_column\", \"module\", \"work_class\", \"business_id\" FROM [sSchema].vm_table INNER JOIN [sSchema].vm_translation as translation_title ON translation_title.translation_id = vm_table.\"title_list_label_id\" INNER JOIN [sSchema].vm_translation as translation_form ON translation_form.translation_id = vm_table.\"title_form_label_id\" and translation_form.lang=translation_title.lang WHERE \"name\" = '[sTable]' AND translation_title.lang = '[sLang]'";
$aSql['pgsql']['getVM_TableInfoTrad'] = "SELECT \"name\", \"id_field\", \"id_field_type\", \"id_field_label\", \"sql_list\", \"form_class\", \"sql_form\", translation_title.\"translation\" as \"TITRE_LISTE\", translation_form.\"translation\" as \"form_title\", \"id_field_sequence\", \"schema_name\", \"sorted_by\", \"sorted_dir\", \"edit_column\" , \"show_column\", \"business_id\" FROM [sSchema].vm_table INNER JOIN [sSchema].vm_translation as translation_title ON translation_title.translation_id = vm_table.\"title_list_label_id\" INNER JOIN [sSchema].vm_translation as translation_form ON translation_form.translation_id = vm_table.\"title_form_label_id\" and translation_form.lang=translation_title.lang WHERE \"name\" = '[sTable]' AND translation_title.lang = '[sLang]'";
$aSql['pgsql']['getVM_LayerInfo'] = "SELECT * FROM [sSchema].vm_table WHERE \"LAYER_NAME\" = '[sLayer]'";
$aSql['pgsql']['getVM_LayerRightInfo'] = "SELECT \"UPDATE\", \"DELETE\", \"INSERT\", \"UPLOAD\", \"EXTRACT\" FROM [sSchema].group_rights LEFT JOIN [sSchema].layer ON group_rights.\"LAYER_ID\" = layer.\"LAYER_ID\" WHERE \"LAYER_NAME\" ='[sLayerName]'  AND \"GROUP_ID\" IN ([iGroupId])";
// getVM_LayerRightInfo_0 DEPRECATED 2011_01
$aSql['pgsql']['getVM_LayerRightInfo_0'] = "SELECT \"UPDATE\", \"UPDATE\" AS \"INSERT\", \"UPDATE\" AS \"DELETE\", \"UPLOAD\", \"EXTRACT\" FROM [sSchema].group_rights LEFT JOIN [sSchema].layer ON group_rights.\"LAYER_ID\" = layer.\"LAYER_ID\" WHERE \"LAYER_NAME\" ='[sLayerName]'  AND \"GROUP_ID\" IN ([iGroupId])";
$aSql['pgsql']['isTableSpatial'] = "SELECT attname, relname, typname, nspname FROM pg_attribute, pg_class, pg_type, pg_namespace WHERE pg_attribute.attrelid = pg_class.oid AND pg_class.relnamespace = pg_namespace.oid AND pg_attribute.atttypid = pg_type.oid AND nspname = '[sSchema]' AND relname = '[sTable]' AND typname = 'geometry' ORDER BY attname ASC";
$aSql['pgsql']['ifTableIsAView'] = "SELECT definition FROM pg_views WHERE schemaname = '[sSchema]' AND viewname = '[sTable]'";
$aSql['pgsql']['getTableSchema'] = "SELECT nspname FROM pg_class, pg_namespace WHERE pg_class.relnamespace = pg_namespace.oid AND relname = '[sTable]'";
$aSql['pgsql']['getTableSrid'] = "SELECT COALESCE(NULLIF(postgis_typmod_srid(pg_attribute.atttypmod), 0), postgis_constraint_srid(pg_namespace.nspname::text, pg_class.relname::text, pg_attribute.attname::text), 0) AS srid FROM pg_class, pg_attribute, pg_type, pg_namespace WHERE pg_type.typname = 'geometry'::name AND pg_attribute.attisdropped = false AND pg_attribute.atttypid = pg_type.oid AND pg_attribute.attrelid = pg_class.oid AND pg_class.relnamespace = pg_namespace.oid AND (pg_class.relkind = 'r'::\"char\" OR pg_class.relkind = 'v'::\"char\") AND NOT pg_is_other_temp_schema(pg_class.relnamespace) AND pg_namespace.nspname = '[sSchema]'::name AND pg_class.relname = '[sTable]'::name;";
$aSql['pgsql']['getTableGeometryType'] = "SELECT replace(replace(COALESCE(NULLIF(upper(postgis_typmod_type(pg_attribute.atttypmod)), 'GEOMETRY'::text), postgis_constraint_type(pg_namespace.nspname::text, pg_class.relname::text, pg_attribute.attname::text)::text, 'GEOMETRY'::text), 'ZM'::text, ''::text), 'Z'::text, ''::text)::character varying(30) AS type FROM pg_class, pg_attribute, pg_type, pg_namespace WHERE pg_type.typname = 'geometry'::name AND pg_attribute.attisdropped = false AND pg_attribute.atttypid = pg_type.oid AND pg_attribute.attrelid = pg_class.oid AND pg_class.relnamespace = pg_namespace.oid AND (pg_class.relkind = 'r'::\"char\" OR pg_class.relkind = 'v'::\"char\") AND NOT pg_is_other_temp_schema(pg_class.relnamespace) AND pg_namespace.nspname = '[sSchema]'::name AND pg_class.relname = '[sTable]'::name;";
$aSql['pgsql']['getTableDimension'] = "SELECT COALESCE(NULLIF(postgis_typmod_dims(pg_attribute.atttypmod), 2), postgis_constraint_dims(pg_namespace.nspname::text, pg_class.relname::text, pg_attribute.attname::text), 2) AS coord_dimension FROM pg_class, pg_attribute, pg_type, pg_namespace WHERE pg_type.typname = 'geometry'::name AND pg_attribute.attisdropped = false AND pg_attribute.atttypid = pg_type.oid AND pg_attribute.attrelid = pg_class.oid AND pg_class.relnamespace = pg_namespace.oid AND (pg_class.relkind = 'r'::\"char\" OR pg_class.relkind = 'v'::\"char\") AND NOT pg_is_other_temp_schema(pg_class.relnamespace) AND pg_namespace.nspname = '[sSchema]'::name AND pg_class.relname = '[sTable]'::name;";
$aSql['pgsql']['getColumnDimension'] = "SELECT COALESCE(NULLIF(postgis_typmod_dims(pg_attribute.atttypmod), 2), postgis_constraint_dims(pg_namespace.nspname::text, pg_class.relname::text, pg_attribute.attname::text), 2) AS coord_dimension FROM pg_class, pg_attribute, pg_type, pg_namespace WHERE pg_type.typname = 'geometry'::name AND pg_attribute.attisdropped = false AND pg_attribute.atttypid = pg_type.oid AND pg_attribute.attrelid = pg_class.oid AND pg_class.relnamespace = pg_namespace.oid AND (pg_class.relkind = 'r'::\"char\" OR pg_class.relkind = 'v'::\"char\") AND NOT pg_is_other_temp_schema(pg_class.relnamespace) AND pg_namespace.nspname = '[sSchema]'::name AND pg_class.relname = '[sTable]'::name AND pg_attribute.attname = '[sColumn]'::name;";
$aSql['pgsql']['getVertexDistance'] = "SELECT st_distance(st_geometryFromText('[sWKT]', [iSRID]), st_geometryFromText('POINT([sVertexCoords])', [iSRID])) as distance";
$aSql['pgsql']['geomAddVertex'] = "SELECT st_asText(st_addPoint(st_geometryFromText('[sWKT]', [iSRID]), st_line_interpolate_point(st_geometryFromText('[sWKT]', [iSRID]), st_line_locate_point(st_geometryFromText('[sWKT]', [iSRID]), st_geometryFromText('POINT([sVertexCoords])', [iSRID]))), vm_get_new_vertex_position(st_geometryFromText('[sWKT]', [iSRID]) ,st_line_interpolate_point(st_geometryFromText('[sWKT]', [iSRID]), st_line_locate_point(st_geometryFromText('[sWKT]', [iSRID]), st_geometryFromText('POINT([sVertexCoords])', [iSRID])))))) as wkt";
$aSql['pgsql']['geomBinding_1'] = "SELECT st_asText(vm_get_nearest_vertex(geom, st_startPoint(st_geometryFromText('[sWKT]', [iSRID])))) as wkt, st_distance(vm_get_nearest_vertex(geom, st_startPoint(st_geometryFromText('[sWKT]', [iSRID]))), st_startPoint(st_geometryFromText('[sWKT]', [iSRID]))) as distance FROM [sSchema].[sTable] WHERE [sWhereClause] st_intersects(geom, st_buffer(st_geometryFromText('[sWKT]', [iSRID]), [dTolerance])) = true ORDER BY distance ASC";
$aSql['pgsql']['geomBinding_2'] = "SELECT st_asText(vm_get_nearest_vertex(geom, st_endPoint(st_geometryFromText('[sWKT]', [iSRID])))) as wkt, st_distance(vm_get_nearest_vertex(geom, st_endPoint(st_geometryFromText('[sWKT]', [iSRID]))), st_endPoint(st_geometryFromText('[sWKT]', [iSRID]))) as distance, st_npoints(st_geometryFromText('[sWKT]', [iSRID])) as nb_vertex FROM [sSchema].[sTable] WHERE [sWhereClause] st_intersects(geom, st_buffer(st_geometryFromText('[sWKT]', [iSRID]), [dTolerance])) = true ORDER BY distance ASC";
$aSql['pgsql']['geomBinding_3'] = "SELECT st_asText(vm_move_vertex_from_geom(st_geometryFromText('[sWKT]', [iSRID]), st_geometryFromText('[sVertexWKT]', [iSRID]), [iVertexIndex])) as wkt";
$aSql['pgsql']['geomCutLine'] = "SELECT st_asText(st_line_substring(st_geometryFromText('[sWKT]', [iSRID]), 0, st_line_locate_point(st_geometryFromText('[sWKT]', [iSRID]), st_geometryFromText('POINT([sVertexCoords])', [iSRID])))) as wkt_start, st_asText(st_line_substring(st_geometryFromText('[sWKT]', [iSRID]), st_line_locate_point(st_geometryFromText('[sWKT]', [iSRID]), st_geometryFromText('POINT([sVertexCoords])', [iSRID])), 1)) as wkt_end";

//Requ�te de la classe Vm pour oci
$aSql['oci']['getVM_TableInfo'] = "SELECT * FROM vm_table WHERE name = '[sTable]'";
?>