Creating class of SQLite - c++

I'm sorry, I'm showing too many lines of code but I just have a small problem.
Take a look at the code file, you'll see two areas which I marked via comment [1] and [2] (Maybe you'll need [3]).
When I run the program, because this is a console program so the screen will have something like:
Befor callback: 0
After callback: 0
It should be After callback: 99 that is what I need.
My question is Why doesn't iResult variable change after I modify it?
Update 1
The 1st agrument of callback function points to where (this) pointer (in [3])points to.
Thank you guys.

When you call run_query to execute your query, it assigned the result of the sqlite3_exec call to iResult. This overwrites the 99 with the result of the query, which is 0.

It's just about everything not optimal about this code. If you're doing something simple, sonsider using an available wrapper, such as hiberlite. There are more low level ones as well.
Try to read about clean code first and about SOLID principles and then about patterns in enterprise software
This is also not what "modern" C++ is good for. Do you really want to do it in C++?
Then, you're doing something dangerous as well - you're assembling a query from a string by not using value binding.

Related

Is there a way to get scrollstate from Lazyrow

I have made a LazyRow that i now want to be able to get the scrollposition from. What i understand Scrollablerow has been deprecated. (correct me if im wrong) The thing is that i cant make a scrollablerow so i thought lets make a lazy one then. but i have no clue how to get scrollposition from the lazyrow. i know how to get index but not position if that eaven exists. here is what i have tried.
val scrollState = rememberScrollState()
LazyRow(scrollState = scrollstate){
}
For LazyScrollers, there are separate LazyStates.
I think there's just one, in fact, i.e. rememberLazyListState()
Pass that as the scroll state to the row and then you can access all kinds of info. For example, you could get the index of the first visible item, as well as its offset. There are direct properties for this stuff in the object returned by the above initialisation. You can also perform some more complex operations using the lazyListState.layoutInfo property that you get.
Also, ScrollableRow may be deprecated as a #Composable, but it is just refactored, a bit. Now, you can use the horozontalScroll() and verticalScroll() Modifiers, both of which accept a scrollState parameter, which expects the same object as the one you've created in the question.
Usually, you'd use LazyScrollers since they're not tough to implement and also are super-performant, but the general idea is that they are used with large datasets whereas non-lazy scrollers are okay for small sized lists and stuff. This is because the lazy ones cache only a small fraction of the entire list, making your UI peformant, which is not something regular scrollers do, and not a problem for small datasets.
They're like equivalents of RecyclerView from the View System

Django - can I sotre and run code from database?

I build program, when in one part I have some ranking, and I would like to give users option to customize it.
In my code I have a function that gets objects and returnes them packed with points and position in ranking (for now it calculates the arithmetic mean of some object's values).
My question is is it possible to give e.g. admin chance to write this function via admin panel and use it, so if he would like to one day use harmonic mean he could without changing source code?
Yes, you could just store a string in the database and exec() it with suitable arguments...
However, you'll have to be careful – Python code can practically never be sandboxed perfectly. In the event that you accept any arbitrary Python code for this, and someone with nefarious intents gets to your admin panel to change the expression, they can do practically anything.
In other words, don't use raw Python for the code you store.

How does one bypass SyntaxError when parsing code?

I am using openpyxl to read an excel file that will have changing values over time. The following function will take string inputs from the excel sheets to make frames for Tkinter.
def make_new_frame(strng, frame_location, frame_name, frame_list):
if not(frame_name in frame_list):
frame_list.append(frame_name)
exec("global %s" %(frame_name)) in globals()
exec("%s = Frame(%s)"%(frame_name, frame_location))
.... etc.
The code itself is quite long but I think this is enough of a snapshot to address my problem.
Now this results in the following error while parsing:
SyntaxError: function 'make_new_frame' uses import * and bare exec, which are illegal because it is a nested function
Everything in the code I included parsed and executed just fine several times, but after I added a few more lines in later versions in this function, it keeps spitting out the above error before executing the code. The error references the third line in the function, (which, I repeat, has been cleared in the past).
I added "in globals()" as recommended in another SO post, so that solution is not working.
There is a solution online here that uses setattr, which I have no idea how to use to create a widget without eventually using exec.
I would really appreciate if someone could tell me how to bypass the error while parsing or provide an alternative means for a dynamically changing set of frame names.
Quick Note:
I am aware that setting a variable as global in python is generally warned against, but I am quite certain that it will serve useful for my code
Edit 1: I have no idea why this was downvoted. If I have done something incorrectly, please let me know what it is so I can avoid doing so in the future.
I think this is an X/Y problem. You are asking for help with solution Y instead of asking for help on problem X.
If your goal is to create an unknown number of Frame objects based on external data, you can store references to the frame in a list or dictionary without having to resort to using exec and dynamically created variable names.
exec is a perfectly fine function, but is one of those things that you should never use until you fully understand why you should never use it.
Here's how to solve your actual problem without using exec:
frames = {}
def make_new_frame(strng, frame_location, frame_name, frames):
if not(frame_name in frames):
frames[frame_name] = Frame(frame_location)
return frames[frame_name]
With that, you now have a dictionary (frames) that includes a reference for every new frame by name. If you had a frame named "foo", for example, you could configure and pack it like this:
frames["foo"].configure(background="red", ...)
frames["foo"].pack(...)
If preserving the order of the frames is important you can use an OrderedDict.

How to find all PointerIds for CoreWindow

Is there a way to get all of the PointerIDs that might be used in the CoreWindow::PointerPressed??
I know that I can get the ID for the Mouse by using:
// This is wrong, see the comment below.
MouseCursorID = CoreWindow::GetForCurrentThread()->PointerCursor->Id
EDIT:
The above block of code gets the 'Resource Id' for CoreCursor. It IS NOT the same thing as the pointer ID!
So how would one go about finding the different Ids for the various pointers? I am especially interested in this because I want to be able to discern input from two different mice, and being able to identify them before receiving events would be a great help.
They will appear as necessary in the various pointer event arguments -- see PointerEventArgs.
You don't know ahead of time how many theoretical pointers there might be. What's the reason that you want to know?

VisualStudio - aliases for very long watch variables

I am trying to debug a tree-like structure, so i have made a watch on each level. The lower i go, the watch variable name is getting ridiculusly long. Is there a way to rename them from:
{,,HTM_Projekt.exe}*(Node*){*}(((*((*(((*((*this).htm)).top)._Myptr)).input)))._Myptr)
to
Level1Node
without more details on how you have it structured. i would suggest you make a varriable of that type that equals what is in your tree and just put that varriable on watch. it just means you will have a little bit of duplicate data but can see what it is clearly.
maybe it would look something like.
Node* kpLevel1Node = (Node*){*}(((*((*(((*((*this).htm)).top)._Myptr)).input)))._Myptr);
and then you just add kpLevel1Node to watch.
EDIT 1:
based off comment.
a pointer is only 4bytes and refrences the same data. but if the extra 4 bytes is not an option for you temporarily while you debug.
then i suggest you use typedef's. to make the long rediculas type into something more readable. and like before without more code showing your implementation an exsact answer is not really possible