I need to know if a locale appcelerator/titanium database exist in an app to be able to migrate data from that DB to ArrowDB.
Is there any way of finding out if a DB exist by its name?
I tried following this answer but didn't succeed.
https://archive.appcelerator.com/question/143890/check-if-local-database-already-exists
// SDK 5.5.0 GA. iOS & Android
Ended up doing this in my index.js as i find it to be a reliable option.
var db = Ti.Database.open("workoutsDB");
try {
var rows = db.execute('SELECT * FROM workouts ORDER BY date DESC');
rows.close();
//If this code block runs the local database exist.
Alloy.Globals.localDatabaseDoesExist = true;
}
catch (error) {
//Gives an sql error when the table does not exist
Alloy.Globals.localDatabaseDoesExist = false;
}
db.close();
Related
I'm looking for a way to store the results of this select query like a "rank" chart for a game but I'm not sure if what I'm encountering is an async issue or a data-type issue or something else entirely. Any thoughts?
var ranksVar = [];
db.all("select * from user", function(err, rows){
if(err) {
throw err;
} else {
setValue(rows);
}
});
function setValue(value) {
ranksVar = value;
console.log(ranksVar);
}
I've found out a useful post about using SQLite with NodeJS and it gives you the basic examples needed to understand how to use it. Here it is: SQLite NodeJS
In your case, look under the section data query.
Here the example code:
const sqlite3 = require('sqlite3').verbose();
// open the database
let db = new sqlite3.Database('./db/chinook.db');
let sql = `SELECT DISTINCT Name name FROM playlists
ORDER BY name`;
db.all(sql, [], (err, rows) => {
if (err) {
throw err;
}
rows.forEach((row) => {
console.log(row.name);
});
});
// close the database connection
db.close();
As you can see, the rows variable is (I guess) a special type created by the module. To get all data from it, you might want to iterate over it and push it into your array variable.
Cheers 😁 !
I figured out the issue. It was a data type/async issue, I was trying to print a string for an undefined array.
Went back a loop and used the JSON.stringify method to display the array objects correctly.
I am using Visual Basic 2008 and Sql Server 2000.
On all Forms I m saving a followup date user select a date and it saved in a relevant table, now at stored follow up date I need to pop up a bar or a notification inside application to tell user that this is you follow up date for this specific record.
Which are the ways I can do it.
any idea will be appreciated
Thanks
I don't understand your question completely. I don't know its for Windows form or Web form (Asp.net) Still I am trying to answer it
You can use SELECT IDENT_CURRENT(‘MyTable’) after your insert command in your stored procedure to get the last inserted id or to verify that it inserted data into table or not.
public int InsertDate(string pid, string followUpDt)
{
Try
{
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("#pid", pid);
param[1] = new SqlParameter("#isScraped", isScraped);
int identityId = (Int32)SqlHelper.ExecuteScalar(CommonCS.ConnectionString, CommandType.StoredProcedure, "Sproc_FollowUpDate_Insert", param);
if(identityId != null)
{
// it means Values has been inserted to the table
// Call a Java Script function to Show popup & message
ScriptManager.RegisterStartupScript(Page,GetType(),"showConfirmPopup","<script>disp_confirm()</script>",false)
}
else
{
//Operation not successful
}
}
}
}
Catch(exception ex)
{
//Log Exception to DB OR Send Error Email
}
///In Aspx
<script type="text/javascript">
function showConfirmPopup() {
var msg = "Successful "
//Show Popup code here
</script>
============================UPDATED ANS====================================
Alright You need to create a SQL Job make it occurring daily at specific time. SQL Job will call a Web service url(Invoke) through Stored Procedure
Check this
Now you can check database dates against current date in that web service.
I was trying to follow this post to query a testcase in a workspace("/workspace/6749437088") that is not the default workspace but the query is not returning that testcase and in fact, not returning anything. Below is the code I am using. If I do a query with 'not equal' the test cases, I notice that it is returning test cases in the user's default workspace. I am using C# and using Rally Rest API Runtime v4.0.30319 and ver 1.0.15.0. Any suggestions? Thanks.
Inserting test case result using Java Rally Rest API failing when workspace is different from default set on account
private string GetRallyObj_Ref(string ObjFormttedId)
{
string tcref = string.Empty;
try
{
string reqType = _Helper.GetRallyRequestType(ObjFormttedId.Substring(0, 2).ToLower());
Request request = new Request(reqType);
request.Workspace = "/workspace/6749437088";
request.Fetch = new List<string>()
{
//Here other fields can be retrieved
"Workspace",
"Name",
"FormattedID",
"ObjectID"
};
//request.Project = null;
string test = request.Workspace;
request.Query = new Query("FormattedID", Query.Operator.Equals, ObjFormttedId);
QueryResult qr = _RallyApi.Query(request);
string objectid= string.Empty;
foreach (var rslt in qr.Results)
{
objectid = rslt.ObjectID.ToString();
break;
}
tcref = "/"+reqType+"/" + objectid;
}
catch (Exception ex)
{
throw ex;
}
return tcref;
Sorry, I found out the issue. I was feeding the code a project ref#, not a workspace ref #. I found out the correct workspace by using pieces of the code in the answer part of this post: Failed when query users in workspace via Rally Rest .net api by querying the workspace refs of the username I am using and there I found out the correct workspace ref. Thanks, Kyle anyway.
The code above seems like it should work. This may be a defect- I'll look into that. In the meantime if you are just trying to read a specific object from Rally by Object ID you should be able to do so like this:
restApi.GetByReference('/testcase/12345',
'Results, 'Verdict', 'Duration' //fetch fields);
I am making a call to the SQL database via Entity Framework, this call takes about 2 mins to execute.
I want to make sure this call only occurs once. Once the call is made, I place the results in cache. I notice if multiple users are on the site, it can be more than 2 mins till the data is returned, whats the best way to approach this? Should I use a mutex? or does Entity Framework (version 4) have any functionality built in to handle this type of situation. I am using MVC 4. Thank you!
public IEnumerable<AdListing> AllActiveAds()
{
try
{
if (PullCache(Constants.CacheKeys.AllActiveAds) == null)
{
using (var db = new MyEntities())
{
db.CommandTimeout = 300;
List<AdListing> results =
(from a in
db.AdListings
.Include("AdPhotos")
.Include("tbLocation")
where !a.Deleted
select a).ToList();
PushCache(results, Constants.CacheKeys.AllActiveAds);
}
}
return (List<AdListing>) PullCache(Constants.CacheKeys.AllActiveAds);
}
catch (Exception ex)
{
HandleException(ex);
return null;
}
}
I'm "trying" to create a Safari Extension that adds links to a local sqlite database.
In the global.html file, I can create the database, but I can't create a table unless I refer to a non-existant variable, which makes the rest of the script fail.
// Global Variable to hold my database
var my_DB;
// Make A Database
init_DB();
// Make A Table
createTable(my_DB);
// Rest of the code
alert("Database and Table have been created!");
// Initialise the Database
function init_DB() {
try {
// Check for Database Support
if (!window.openDatabase) {
alert("Database functionality is NOT Supported!");
} else {
// Setup the database
var shortName = "imp_DB";
var version = '1.0';
var displayName = "My Important Database";
var maxSize = 65536; // in bytes
var theDB = openDatabase(shortName, version, displayName, maxSize);
}
} catch(e) {
// Error Handling
if (e == "INVALID_STATE_ERR") {
// We have a version number mismatch
alert("Invalid database version");
} else {
// Unknown error
alert("Unknown error: " + e);
}
return;
}
// Assign the database to the global variable
my_DB = theDB;
}
// Create The Table
function createTable(thisDB) {
thisDB.transaction(function(txn) {
txn.executeSql('CREATE TABLE IF NOT EXISTS people (id unique, name, age)');
});
// The following line is the problem
someVar = txn;
}
Calling init_DB() works fine, and the database is created. However, calling createTable(my_DB) just fails silently, (No Errors, or Warnings) and the rest of the code completes, UNLESS I refer to "txn" somehow.
So adding the "SomeVar = txn;" line allows the Table to be created, but unfortunately, it causes "ReferenceError: Can't find variable: txn" to appear in the console, and stops the rest of the code from running.
Does anyone have any ideas? I've been trying to get this to work for over a week, and I'm at my wit's end.
Thanks in advance for any suggestions ;-)
N.B. Declaring "txn" before attempting to create a Table also causes a silent fail.