Escape double quote Character in Kognitio - kognitio-wx2

It seems that the Kognito console use this template for password reset (also create user)
ALTER USER user_name ALTER PASSWORD TO " "; -- we cannot include a " character in the password which would end up in syntax error.
How do we escape this and include a " character

Finally found one solution from the manual
ALTER USER user_name ALTER PASSWORD TO 'Pass"word' ESCAPE '"';

Related

Check if string has at least one alphanumeric character

I'm an absolute beginner trying to learn string validation. I have a variable about to store user input:
Text_input = raw_input('Type anything: ')
I want to check if Text_input contains at least one alphanumeric character. (If not, the program should print a message such as "Try again!" and ask the user to type again.) So, typing "A#" should pass but "#" should not. Any suggestions?
This worked for me:
Text_input = raw_input('Type anything: ')
if any(char.isalpha() or char.isdigit() for char in Text_input):
print "Input contains at least one alphanumeric character."
else:
print "Input must contain at least one alphanumeric character."

uppercasing a character in string with a letter of users choosing

I'm pretty new to programming in python, so this is giving me problems. I'm searching for a way to uppercase a letter of a user's choosing in a word of user's choosing. For example, user writes staircase and as character he writes a and the end result would be stAircAse.
I know the code to ask user a question
promt='enter word:\n'
originalString=raw_input(promt)
promt='enter a character:\n'
upperCharacter=raw_input(promt)
But other then that I'm lost and would appreciate help.
i tried this code, but its not the user input of a letter to upper case
def chartoupper(instring,inchar):
indexes=[3,7]
chars=list(originalString)
for i in indexes:
chars[i]=chars[i].upper()
string=''.join(chars)
return string
promt='enter word:\n'
originalString=raw_input(promt)
promt='enter a character:\n'
upperCharacter=raw_input(promt)
newstring=chartoupper(originaString,upperCharacter)
print originaString
print upperCharacter
print newstring
print inchar
Try this -
if(len(upperCharacter) == 1):
finalString = originalString.replace(upperCharacter, upperCharacter.upper())
print finalString
As you should check if the user has indeed just added a single character, we added the if condition.
We are replacing all the occurrences of the character upperCharacter in originalString and assigning it to finalString. Refer the docs for this method
Answer for edited question --
def chartoupper(instring, inchar):
string = instring.replace(inchar, inchar.upper())
return string
promt='enter word:\n'
originalString=raw_input(promt)
promt='enter a character (note that only the 1st character will be used):\n'
upperCharacter=raw_input(promt)[0]
newstring=chartoupper(originalString, upperCharacter)
print originalString
print upperCharacter
print newstring

How do I find all instances that have field: "username" inequivalent to its stripped "username"

In a pseudo-query, it would look something like this:
User.objects.filter(username != username.strip())
Example usernames that would match this search:
"hello "
" hello"
" hello "
Example usernames that would NOT match this search:
"hello"
"hello world"
Examples are not exhaustive (i.e. the whitespace can be in the form of tabs, newlines, etc).
Why are you storing usernames in your database with leading and trailing spaces? Trim them before you insert them instead of allowing dirty data in your database.
But to answer your question directly, you don't need to use extra to do a regular expression lookup, as the queryset API natively supports it.
This should do what you want:
User.objects.filter(username__regex=r"\s*" + user + r"\s*")
Things get a little messy on SQLLite, where regex lookups aren't natively supported, but it still works.
extra can be used. This is what it would look like for PostgreSQL:
User.objects.extra(where=["username != regexp_replace(username, '^\s+|\s+$', '', 'g')"])
from django.db.models import Q
User.objects.filter(Q(username__startswith=' ') | Q(username__endswith=' '))

regex to match some string

I am working a project that need to match certain string in the output..
here the sample:
user code timestamp Action Name S#TPLC Field Name User code group profile
SNGLASK 2012-05-30-20.33.53.003000 Insert User I TEST5 DISPLAY
SNGLASK 2012-05-23-22.06.44.422000 Change Password RSO part U LERAPR SNGCHIS FULL_AUTH
SNGLASK 2012-05-30-20.34.39.066000 Insert User Group Profil I *NONE
basically i have a application that need to understand that each row after the space is belong to next column.
Then, after action name everything can be treated as other.
hence, i have come out a regex format like below:
REGEX = ^([^\s]+)\s+([^\s]+)\s+([^\s]+)s(.*)$
FORMAT = userCode::"$1" TimeStamp::"$2" ActionName::"$3" Others::"$4"
The strategy is recognize the string then ignore the space after that. However, this thing work until action name as they might be space between the action name.
Hence, my problem is, how to use regex to let it recognize the string within the action name like i need "insert user" as an input & "change password RSO part" as another input.
Do multipart words like this:
((\S+\s)+)
which says one or more word, separated with one space.
so the regex whould be:
^((\S+\s)+)\s+(\S+)\s+((\S+\s)+)\s+(.*)$

Search and Replace "(" " " and "[" in Vi - Regex

I have this line:
[app_user] ([id], [nome], [email], [login], [senha], [tipo], [data])
I want to replace for this:
(id, name, email_address, username, password, access_type, created)
How I do that?
I try this (in vi):
:%s/\[app_user\] \+\\( \[id\], \+\[nome\], \+\[email\], \+\[login\], \+\[senha\], \+\[tipo\], \+\[data\]\\) /\\( id,name,email_address,username,password,access_type\\)/
But didn't work.
I think the problem is betwen " \+//(", because I try run, only simple search:
/\[app_user\] \+
And works.
I'm not expert in Regex.
To disable all special characters except the backslash in your search pattern use \V (very nomagic), that would make much easier to write it:
:%s/\V[app_user] ([id], [nome], [email], [login], [senha], [tipo], [data])/(id, name, email_address, username, password, access_type, created)