I am wondering what is the extent of functionality that add-ons/plugins can provide with Firefox. For example, can we edit the way Firefox reads and writes to its Sqlite database?
I am considering a project where we would encrypt the contents of this database when writing to it, and decrypt from it when reading from it. It would be cool if we could do this through the use of a plugin or add-on. Does anyone know if this is feasible or not?
You can create a new SQLLite DB and write to it via a firefox plugin. See https://developer.mozilla.org/en/storage
I've done this previously for a Firebug plugin that I've created. From your plugin you do something like this:
var file = Components.classes["#mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
file.append("rttplog.sqlite");
var storageService = Components.classes["#mozilla.org/storage/service;1"]
.getService(Components.interfaces.mozIStorageService);
this.mDBConn = storageService.openDatabase(file);
this.mDBConn.executeSimpleSQL("CREATE TEMP TABLE log (id INTEGER, type VARCHAR, message TEXT)");
Inserting:
var statement = this.mDBConn.createStatement("INSERT INTO log VALUES(:id, :type, :message)");
statement.params.id = id;
statement.params.type = type;
statement.params.message = message;
statement.execute();
Selecting:
var statement = this.mDBConn.createStatement("SELECT id FROM log WHERE message LIKE :query ESCAPE '/' ");
var escaped = statement.escapeStringForLIKE(query, "/");
statement.params.query = "%" + escaped + "%";
return statement.executeAsync(callback);
Hope that helps.
Related
i am trying to add firebase into my react-native application, and have the following code:
_saveFile(fileName){
var userPath = "/Users/Johnny/files/";
var storageString = ("Johnny Johnson\n"+ date + "\n" +
this.state.text);
var name = fileName;
firebase.database().ref(userPath).set({
name : storageString
})
}
But as you can probably guess, this isn't getting the name variable and storing it as the key. It is simply storing it in the database as..
Users -> Johnny -> files -> {name: "whatever the string was i saved"}
and then simply overriding it every time i try and make a new file. Just wondering how i go about parsing in this fileName variable? It is getting the child value correctly - which is why i am confused.
Any help would be appreciated, i'm pretty new to this.
If you put brackets around name it will use the name variable instead of creating a key called name.
firebase.database().ref(userPath).set({
[name] : storageString
})
I'm trying to make a search form to use on an api. However when the user types in the search field more then one name I want it to break the string into pieces and make a new string with a + between every keyword. I have no idea how to do this however.
Try this
var searchString:String = "nameOne nameTwo nameThree";
var whiteSpacePattern:RegExp = /\s+/g;
var replacedString:String = searchString.replace(whiteSpacePattern, "+");
trace(replacedString); // nameOne+nameTwo+nameThree
More information about String.replace : http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f00.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7ef1
I have a form built in webmatrix that will be updating data within a user specified database.
I would like the user to insert their DB name into the form, and have the Database.Open("SQLServerConnectionString"); open based on the users submission.
if not possible, is there a way to simply include the user specified DB name within the SQL query below within webmatrix? Sample of what I have below:
var db = Database.Open("SQLServerConnectionString");
var selectQueryString = "SELECT donor_id,first_name,last_name FROM SUPPORT.dpo.dp WHERE donor_id=#0";
I would like the static "SUPPORT" database in the FROM clause to be updated dynamically based on user input. Any help would be great.
Are you using .mdf files or actual database connection strings? If connection strings you can use the OpenConnectionString method and pass a custom connection string instead of using whats in the web.config.
http://msdn.microsoft.com/en-us/library/gg569301(v=VS.99).aspx
Something like this would probably work:
#{
var databaseName = Request["databaseName"]; //load from request
var connectionString = string.Format("Data Source=.\\SQLExpress;Initial Catalog={0};Integrated Security=True", databaseName);
var providerName = "System.Data.SqlClient";
var db = Database.OpenConnectionString(connectionString, providerName);
var selectQueryString = "SELECT * FROM Product ORDER BY Name";
}
You can just drop the SUPPORT. prefix as its not necessary for the select statement.
I am using SQLite for Windows Phone 7 (http://sqlitewindowsphone.codeplex.com/) and I have done every steps from this tutorial (http://dotnetslackers.com/articles/silverlight/Windows-Phone-7-Native-Database-Programming-via-Sqlite-Client-for-Windows-Phone.aspx)
Then I try to make some simple application with basic features like select and delete. App is working properly till I want to make one of this operations. After I click select or delete, compiler shows me errors that he is unable to open database file...
I have no idea why?
I used the same Sqlite client, and had the same problem. This problem occurs because the sqlite try to create file in IsolatedFileStorage "DatabaseName.sqlite-journal" and it does not have enough permissions for that. I solved the problem, so that created "DatabaseName.sqlite-journal" before copying database to IsolatedFileStorage. Here's my method that did it:
private void CopyFromContentToStorage(String assemblyName, String dbName)
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
string uri = dbName + "-journal";
store.CreateFile(uri);
using (Stream input = Application.GetResourceStream(new Uri("/" + assemblyName + ";component/" + dbName,UriKind.Relative)).Stream)
{
IsolatedStorageFileStream dest = new IsolatedStorageFileStream(dbName, FileMode.OpenOrCreate, FileAccess.Write, store);
input.Position = 0;
CopyStream(input, dest);
dest.Flush();
dest.Close();
dest.Dispose();
}
}
it helped me, and worked well.
hope this will help you
Are you sure the file exists?
You can check like that:
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
exists = store.FileExists(DbfileName);
}
I've written a database generation script in SQL and want to execute it in my Adobe AIR application:
Create Table tRole (
roleID integer Primary Key
,roleName varchar(40)
);
Create Table tFile (
fileID integer Primary Key
,fileName varchar(50)
,fileDescription varchar(500)
,thumbnailID integer
,fileFormatID integer
,categoryID integer
,isFavorite boolean
,dateAdded date
,globalAccessCount integer
,lastAccessTime date
,downloadComplete boolean
,isNew boolean
,isSpotlight boolean
,duration varchar(30)
);
Create Table tCategory (
categoryID integer Primary Key
,categoryName varchar(50)
,parent_categoryID integer
);
...
I execute this in Adobe AIR using the following methods:
public static function RunSqlFromFile(fileName:String):void {
var file:File = File.applicationDirectory.resolvePath(fileName);
var stream:FileStream = new FileStream();
stream.open(file, FileMode.READ)
var strSql:String = stream.readUTFBytes(stream.bytesAvailable);
NonQuery(strSql);
}
public static function NonQuery(strSQL:String):void {
var sqlConnection:SQLConnection = new SQLConnection();
sqlConnection.open(File.applicationStorageDirectory.resolvePath(DBPATH));
var sqlStatement:SQLStatement = new SQLStatement();
sqlStatement.text = strSQL;
sqlStatement.sqlConnection = sqlConnection;
try {
sqlStatement.execute();
} catch (error:SQLError) {
Alert.show(error.toString());
}
}
No errors are generated, however only tRole exists. It seems that it only looks at the first query (up to the semicolon- if I remove it, the query fails). Is there a way to call multiple queries in one statement?
I wound up using this. It is a kind of a hack, but it actually works pretty well.
The only thing is you have to be very careful with your semicolons. : D
var strSql:String = stream.readUTFBytes(stream.bytesAvailable);
var i:Number = 0;
var strSqlSplit:Array = strSql.split(";");
for (i = 0; i < strSqlSplit.length; i++){
NonQuery(strSqlSplit[i].toString());
}
The SQLite API has a function called something like sqlite_prepare which takes one statement and prepares it for execution, essentially parsing the SQL and storing it in memory. This means that the SQL only has to be sent once to the database engine even though the statement is executed many times.
Anyway, a statement is a single SQL query, that's just the rule. The AIR SQL API doesn't allow sending raw SQL to SQLite, only single statements, and the reason is, likely, that AIR uses the sqlite_prepare function when it talks to SQLite.
What about making your delimiter something a little more complex like ";\n" which would not show up all that often. You just have to ensure when creating the file you have a line return or two in there. I end up putting two "\n\n" into the creation of my files which works well.