How can insert Cutout sign ( ' ) sqlite database from a txt file - sqlite

I used sqlite database to save my data. I backuped sqlite table to a txt file. When I try to restore from txt to sqlite I get syntax error (code-1) . Because I used cutout sign ( ' ) for example when I writing (Türk'ler geldi).
Error is : android.database.sqlite.SQLiteException: near "ler": syntax error (code 1): , while compiling: .......
How can I insert it. I used ( \' ) but it didn't work.
Here is my code from sqlite to txt file
semptoms = db.allSemptom();
int say = semptoms.size();
StringBuilder message = new StringBuilder("");
for (int i = 0; i < say; i++) {
Semptom semptom = semptoms.get(i);
String name = semptom.getName();
message.append(name + "\n");
}
saveToSymptom(message.toString());
I try to add .replace(" ' "," \ ' ") but didn't work
I mean like this
message.append(name.replace(" ' "," \ ' ") + "\n")

Thanks to forpas for this answer
I used the below code and now problem solved.
message.append(name.replace("'","''") + "\n")
as forpas said in comment

Related

Jgit how to get files in a specific commit

I am trying to get list of commits during a specfic period and trying to get the list of files in each commit . Tried below code
gitRepo = Git.cloneRepository().setURI("****").setCredentialsProvider(
new UsernamePasswordCredentialsProvider("PRIVATE-TOKEN", "***")).setDirectory(new File("test")).setNoCheckout(true).call();
ObjectId masterId = gitRepo.getRepository().exactRef("refs/remotes/origin/master").getObjectId();
Date since = new SimpleDateFormat("yyyy-MM-dd").parse("2021-12-08");
Date until = new SimpleDateFormat("yyyy-MM-dd").parse("2021-12-10");
RevFilter between = CommitTimeRevFilter.between(since, until);
for (RevCommit commit : gitRepo.log().add(masterId).setRevFilter(between).call()) {
System.out.println( "* "
+ commit.getId().getName()
+ " "
+ commit.getShortMessage()
+ " "
+ commit.getAuthorIdent().getName());
ObjectId lastCommitId = gitRepo.getRepository().resolve(commit.getId().getName());
RevTree tree = commit.getTree();
TreeWalk treeWalk = new TreeWalk(gitRepo.getRepository());
treeWalk.addTree(tree);
treeWalk.setRecursive(false);
while(treeWalk.next()){
System.out.println("File Name = "+treeWalk.getPathString());
}
}
Its getting all files in the repo instead of the files changed as part of the specific commit I am passing in last commit . Not sure what I am missing ?

How can I read/decrypt the encrypted_value column in the chrome sqlite database using powershell?

I'm trying to read the contents of a cookie (to use for authentication in a script), but the value is stored as some sort of encrypted value in the chrome sqlite database. Is there any way to decrypt this using powershell?
Right now I can read the value out of the database using a script like this:
[string]$sqlite_library_path = "C:\Path\To\System.Data.SQLite.dll"
[string]$db_data_source = "C:\Users\$env:USERNAME\AppData\Local\Google\Chrome\User Data\Default\Cookies"
[string]$db_query = "SELECT * FROM cookies WHERE name='cookiename' AND host_key='servername'"
[void][System.Reflection.Assembly]::LoadFrom($sqlite_library_path)
$db_dataset = New-Object System.Data.DataSet
$db_data_adapter = New-Object System.Data.SQLite.SQLiteDataAdapter($db_query,"Data Source=$db_data_source")
[void]$db_data_adapter.Fill($db_dataset)
$db_dataset.Tables[0].encrypted_value
The problem is that the encryped value that is returned is unusable. How can I convert this into a usable value?
Adapted to Powershell from this answer: Encrypted cookies in Chrome
# Load System.Security assembly
Add-Type -AssemblyName System.Security
# Decrypt cookie
$ByteArr = [System.Security.Cryptography.ProtectedData]::Unprotect(
$db_dataset.Tables[0].encrypted_value,
$null,
[System.Security.Cryptography.DataProtectionScope]::CurrentUser
)
# Convert to string
$DecryptedCookie = [System.Text.Encoding]::ASCII.GetString($ByteArr)
I also advise you to change the way you getting the path to the cookies DB, because it's unreliable. In fact, it doesn't works on my machine, because, I've renamed user, but profile folder still keeps it's old name. Use Environment.GetFolderPath method instead:
# Get Cookies DB path
[string]$db_data_source = Join-Path -Path [Environment]::GetFolderPath('LocalApplicationData') -ChildPath 'Google\Chrome\User Data\Default\Cookies'
For those who don't have/want a SQLite assembly, you can use the sqlite command.
Here's a working 1-line example for Bash on MSYS2 (spread over multiple lines for readability).
Fill in the '' blanks in the SQL query as needed.
sqlite3 "${LOCALAPPDATA}\\Google\\Chrome\\User Data\\Default\\Cookies" \
".mode quote" \
"SELECT encrypted_value FROM cookies WHERE host_key = '' AND name = '' AND path = '/'"|\
powershell -command 'function main() {
$newline = [System.Text.Encoding]::ASCII.GetBytes(([char]10).ToString());
$stdout = [System.Console]::OpenStandardOutput();
try {
for ($n = 0; ($s = [System.Console]::In.ReadLine()) -ne $null; ++$n) {
if ($n) { $stdout.Write($newline, 0, $newline.Length); }
$s = [System.Text.RegularExpressions.Regex]::Match($s,
"^X" + [char]39 + "(.*)" + [char]39 + "$").Groups[1].Value;
$b = [byte[]]::new($s.Length / 2);
For ($i=0; $i -lt $s.Length; $i += 2) {
$b[$i / 2] = [System.Convert]::ToByte($s.Substring($i, 2), 16);
}
Add-Type -AssemblyName System.Security;
$output = [System.Security.Cryptography.ProtectedData]::Unprotect($b, $null,
[System.Security.Cryptography.DataProtectionScope]::CurrentUser);
$stdout.Write($output, 0, $output.Length);
}
} finally {
$stdout.Close();
}
}
main'

how can i recover the error(Could not find a part of the path 'E:\Work Station\Works\NewThrissurDiary\images\'.) that i got in my update query?

I want to update the files which I uploaded to database
This is my query.. please help...
if (FileUpload1.HasFile || FileUpload2.HasFile || FileUpload3.HasFile || FileUpload4.HasFile || FileUpload5.HasFile)
{
string filename1 = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Server.MapPath("~/images/" + filename1));
string filename2 = Path.GetFileName(FileUpload2.PostedFile.FileName);
FileUpload2.SaveAs(Server.MapPath("~/images/" + filename2));
string filename3 = Path.GetFileName(FileUpload3.PostedFile.FileName);
FileUpload3.SaveAs(Server.MapPath("~/images/" + filename3));
//string filename4 = Path.GetFileName(FileUpload4.PostedFile.FileName);
//FileUpload4.SaveAs(Server.MapPath("~/images/" + filename4));
string filename5 = Path.GetFileName(FileUpload5.PostedFile.FileName);
FileUpload5.SaveAs(Server.MapPath("~/images/" + filename5));
}
even It is an old Topic....
But I have recently gotten same Error... The Error Try to access the pathe which is not available. Let me say as my example :
I Have a folder (Fa) which belongs to My Experts and The main Path where records upload files are In another folder (Fb)...
At First I wrote this Code :
string strname2;
strname2 = ("Fa/" + FileUpload2.PostedFile.FileName.Substring(FileUpload2.PostedFile.FileName.LastIndexOf("//") + 1));
LabelFile.Text = strname2;
and when I use Following Error I got that deadly Error :
if (strname2 != "Fa/")
{
FileUpload2.PostedFile.SaveAs(Server.MapPath(strname2));
}
else
{
LabelFile.Text = "";
}
After some test and try I change both above code to following Codes and Guess what? Everything works like a charm :
1:
string strname2;
strname2 = ("../Fb/Fa/" + FileUpload2.PostedFile.FileName.Substring(FileUpload2.PostedFile.FileName.LastIndexOf("//") + 1));
LabelFile.Text = strname2;
And then:
2:
if (strname2 != "../Fb/Fa/")
{
FileUpload2.PostedFile.SaveAs(Server.MapPath(strname2));
}
else
{
LabelFile.Text = "";
}
Now the solution is check your folders and see that folders are available or not.
PS: Search specially for this folder : NewThrissurDiary
Hope this Help you

Show Log of a file in jgit when committng it as a BLOB

Implemented the above logic to create a new commit (with no parents) that contains only my file. Commits are fast in the repository as compared to CommitCommand commit = git.commit();
But I am not able to get the Logs of a particular file , the number of times it has been updated/revised , and every time i go for Constants.HEAD , I am getting null.
Any help will be of great advantage.
Git git = jGitUtil.openRepo();
Repository repository = git.getRepository();
ObjectInserter repoInserter = repository.newObjectInserter();
ObjectId commitId = null;
try
{
byte[] fileBytes= FileUtils.readFileToByteArray(sourceFile);
// Add a blob to the repository
ObjectId blobId = repoInserter.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, fileBytes);
// Create a tree that contains the blob as file "hello.txt"
TreeFormatter treeFormatter = new TreeFormatter();
treeFormatter.append(actualFileName, FileMode.REGULAR_FILE, blobId);
ObjectId treeId = treeFormatter.insertTo(repoInserter);
System.out.println("File comment : " + relativePath + PortalConstants.FILESEPARATOR + actualFileName + PortalConstants.EP_DELIMETER + userComments);
// Create a commit that contains this tree
CommitBuilder commit = new CommitBuilder();
PersonIdent ident = new PersonIdent(user.getFirstName(), user.getUserId());
commit.setCommitter(ident);
commit.setAuthor(ident);
commit.setMessage(relativePath + PortalConstants.FILESEPARATOR + actualFileName + PortalConstants.EP_DELIMETER + userComments);
commit.setTreeId(treeId);
commitId = repoInserter.insert(commit);
System.out.println(" commitId : " + commitId.getName());
repoInserter.flush();
System.out.println("Flush Done");
}catch(IOException ioe){
log.logError(StackTraceUtil.getStackTrace(ioe));
System.out.println(StackTraceUtil.getStackTrace(ioe));
}
finally
{
repoInserter.release();
}
return commitId.getName();
}
I would probably use Add File and Commit File porcelain commands instead of trying to implement it myself. Then retrieving the log should be possible via something like this:
Iterable<RevCommit> logs = new Git(repository).log()
.all()
.call();
for(RevCommit rev : logs) {
System.out.println("Commit: " + rev + " " + rev.getName() + " " + rev.getId().getName());
}
Where you can retrieve the additional information based on the commit-id.
I have now also added this as new snippet Show Log
Note that if you are creating a commit with no parents, you are saying that there is no history. Therefore you won't be able to see any other changes from that history because it doesn't exist.
You probably should use a commit with the parent of the current position of the branch so that you'll be able to get more information.

ado.net query removes file exention when adding string filename to the database

I am using the code below for saving uploaded picture and makigna thumbnail but it saves a filename without the extension to the database, therefore, I get broken links. How can I stop a strongly typed dataset and dataadapter to stop removing the file extension? my nvarchar field has nvarchar(max) so problem is not string length.
I realized my problem was the maxsize in the dataset column, not sql statement parameter, so I fixed it. You may vote to close on this question.
hasTableAdapters.has_actorTableAdapter adp1 = new hasTableAdapters.has_actorTableAdapter();
if (Convert.ToInt16(adp1.UsernameExists(username.Text)) == 0)
{
adp1.Register(username.Text, password.Text,
ishairdresser.Checked, city.Text, address.Text);
string originalfilename = Server.MapPath(" ") + "\\pictures\\" + actorimage.PostedFile.FileName;
string originalrelative = "\\pictures\\" + actorimage.FileName;
actorimage.SaveAs(originalfilename);
string thumbfilename = Server.MapPath(" ") + "\\pictures\\t_" + actorimage.PostedFile.FileName;
string thumbrelative = "\\pictures\\t_" + actorimage.FileName;
Bitmap original = new Bitmap(originalfilename);
Bitmap thumb=(Bitmap)original.GetThumbnailImage(100, 100,
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback),
IntPtr.Zero);
thumb=(Bitmap)original.Clone(
new Rectangle(new Point(original.Width/2,original.Height/2), new Size(100,100)),
System.Drawing.Imaging.PixelFormat.DontCare);
/*
bmpImage.Clone(cropArea,bmpImage.PixelFormat);
*/
thumb.Save(thumbfilename);
adp1.UpdatePicture(originalrelative, thumbrelative, username.Text);
LoginActor();
Response.Redirect("Default.aspx");
}
}
Looks like the problem is you are using HttpPostedFile.FileName property, which returns fully-qualified file name on the client. So, this code string originalfilename = Server.MapPath(" ") + "\\pictures\\" + actorimage.PostedFile.FileName; generates something like this:
c:\inetpub\pictures\c:\Users\Username\Pictures\image1.jpg
Use FileUpload.FileName property everywhere and you will probably get what you want.
Use this to get Image or file extension :
string Extension = System.IO.Path.GetExtension(FileUpload.FileName);

Resources