<commit_before>$(function () {


	/***************
		ROUTER
	 ***************/
	 
	var Router = Backbone.Router.extend({	
	
		routes: {
			"!:db_type_id":	"DBType", // #!1
			"!:db_type_id/:short_code":"SchemaDef", // #!1/abc12
			"!:db_type_id/:short_code/:query_id":"Query" // #!1/abc12/1
		},
		
		DBType: function (db_type_id) {
			// update currently-selected dbtype
			window.dbTypes.setSelectedType(db_type_id, true);
			window.dbTypesListView.render();
		},
		
		SchemaDef: function (db_type_id, short_code) {

			var frag = "!" + db_type_id + "/" + short_code;
		
			this.DBType(db_type_id);
			$("body").block({ message: "Loading..."});
			$.getJSON("index.cfm/fiddles/loadContent", {fragment: frag}, function (resp) {
				window.schemaDef.set({
					"short_code": resp["short_code"],
					"ddl": resp["ddl"],
					"ready": true,
					"valid": true,
					"errorMessage": ""
				});
				window.schemaDef.trigger("reloaded");
				window.schemaDef.trigger("built");				
				window.query.reset();
				window.query.trigger("reloaded");		
				
				window.myFiddleHistory.insert(new UsedFiddle({
					"fragment": frag,
					"full_name": window.dbTypes.getSelectedType().get("full_name"),
					"ddl": resp["ddl"] 
				}));
				
				$("body").unblock();
						
			});
			
		},
		
		Query: function (db_type_id, short_code, query_id) {
			var frag = "!" + db_type_id + "/" + short_code + "/" + query_id;
		
			this.DBType(db_type_id);

			$("body").block({ message: "Loading..."});
			$.getJSON("index.cfm/fiddles/loadContent", {fragment: frag}, function (resp) {
				window.schemaDef.set({
					"short_code": resp["short_code"],
					"ddl": resp["ddl"],
					"ready": true,
					"valid": true,
					"errorMessage": ""
				});
				window.schemaDef.trigger("reloaded");
				
				window.query.set({
					"id": query_id,
					"sql": resp["sql"],
					"sets": resp["sets"]
				});
				window.query.trigger("reloaded");

				window.myFiddleHistory.insert(new UsedFiddle({
					"fragment": frag,
					"full_name": window.dbTypes.getSelectedType().get("full_name"),
					"ddl": resp["ddl"],
					"sql": resp["sql"] 
				}));
						
				
				
				$("body").unblock();
			});

		
		}
	
	});
	
	/***************
		MODELS
	 ***************/
	
	var UsedFiddle = Backbone.Model.extend({
		defaults: {
			"fragment": "",
			"full_name": "",
			"ddl": "",
			"sql": "" 
		},
		initialize: function () {
			this.set("last_used", new Date());
		}
	});
	<commit_msg>Handling cases when unexpected results returned from loadContent<commit_after>$(function () {


	/***************
		ROUTER
	 ***************/
	 
	var Router = Backbone.Router.extend({	
	
		routes: {
			"!:db_type_id":	"DBType", // #!1
			"!:db_type_id/:short_code":"SchemaDef", // #!1/abc12
			"!:db_type_id/:short_code/:query_id":"Query" // #!1/abc12/1
		},
		
		DBType: function (db_type_id) {
			// update currently-selected dbtype
			window.dbTypes.setSelectedType(db_type_id, true);
			window.dbTypesListView.render();
		},
		
		SchemaDef: function (db_type_id, short_code) {

			var frag = "!" + db_type_id + "/" + short_code;
		
			this.DBType(db_type_id);
			$("body").block({ message: "Loading..."});
			$.getJSON("index.cfm/fiddles/loadContent", {fragment: frag}, function (resp) {
				if (resp["short_code"])
				{
					window.schemaDef.set({
						"short_code": resp["short_code"],
						"ddl": resp["ddl"],
						"ready": true,
						"valid": true,
						"errorMessage": ""
					});
					window.schemaDef.trigger("reloaded");
					window.schemaDef.trigger("built");				
					window.query.reset();
					window.schemaDef.trigger("reloaded");
					
					window.myFiddleHistory.insert(new UsedFiddle({
						"fragment": frag,
						"full_name": window.dbTypes.getSelectedType().get("full_name"),
						"ddl": resp["ddl"] 
					}));
				}
				$("body").unblock();
						
			});
			
		},
		
		Query: function (db_type_id, short_code, query_id) {
			var frag = "!" + db_type_id + "/" + short_code + "/" + query_id;
		
			this.DBType(db_type_id);

			$("body").block({ message: "Loading..."});
			$.getJSON("index.cfm/fiddles/loadContent", {fragment: frag}, function (resp) {

				if (resp["short_code"])
				{

					window.schemaDef.set({
						"short_code": resp["short_code"],
						"ddl": resp["ddl"],
						"ready": true,
						"valid": true,
						"errorMessage": ""
					});
					window.schemaDef.trigger("reloaded");
					
					if (resp["sql"])
					{
						window.query.set({
							"id": query_id,
							"sql": resp["sql"],
							"sets": resp["sets"]
						});
						window.query.trigger("reloaded");
		
						window.myFiddleHistory.insert(new UsedFiddle({
							"fragment": frag,
							"full_name": window.dbTypes.getSelectedType().get("full_name"),
							"ddl": resp["ddl"],
							"sql": resp["sql"] 
						}));
					}							
				
				}
				$("body").unblock();
			});

		
		}
	
	});
	
	/***************
		MODELS
	 ***************/
	
	var UsedFiddle = Backbone.Model.extend({
		defaults: {
			"fragment": "",
			"full_name": "",
			"ddl": "",
			"sql": "" 
		},
		initialize: function () {
			this.set("last_used", new Date());
		}
	});
	
{'fraction_non_alphanumeric': 0.2192209825797612, 'fraction_numerical': 0.0031317283225680173, 'mean_word_length': 2.7936154417223458, 'pattern_counts': {'":': 54, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4487531', 'n_tokens_mistral': 2377, 'n_tokens_neox': 1790, 'n_words': 263}